无服务器框架、打字稿、nodejs 和 mysql - 错误:接收到的数据包顺序错误
Posted
技术标签:
【中文标题】无服务器框架、打字稿、nodejs 和 mysql - 错误:接收到的数据包顺序错误【英文标题】:serverless framework, typescript, nodejs and mysql - Error: Received packet in the wrong sequence 【发布时间】:2018-12-30 10:38:24 【问题描述】:使用安装的mysqljs/mysql调用函数时
npm install --save-dev mysql
我得到以下错误和跟踪。
"errorMessage": "RequestId: be7822cc-8e1d-11e8-83b8-a1383ecfa1de Process exited before completing request"
--------------------------------------------------------------------
START RequestId: be7822cc-8e1d-11e8-83b8-a1383ecfa1de Version: $LATEST
2018-07-22 19:11:46.308 (-07:00) be7822cc-8e1d-11e8-83b8-a1383ecfa1de Error: Received packet in the wrong sequence.
at N._parsePacket (/var/task/controllers/webpack:/node_modules/mysql/lib/protocol/Protocol.js:270:1)
at N.write (/var/task/controllers/webpack:/node_modules/mysql/lib/protocol/Parser.js:76:1)
at N.write (/var/task/controllers/webpack:/node_modules/mysql/lib/protocol/Protocol.js:38:1)
at Socket.<anonymous> (/var/task/controllers/webpack:/node_modules/mysql/lib/Connection.js:91:1)
at Socket.<anonymous> (/var/task/controllers/webpack:/node_modules/mysql/lib/Connection.js:502:1)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
END RequestId: be7822cc-8e1d-11e8-83b8-a1383ecfa1de
REPORT RequestId: be7822cc-8e1d-11e8-83b8-a1383ecfa1de Duration: 2514.52 ms Billed Duration: 2600 ms Memory Size: 128 MB Max Memory Used: 46 MB
RequestId: be7822cc-8e1d-11e8-83b8-a1383ecfa1de Process exited before completing request
我的示例代码是
import APIGatewayEvent, Callback, Context, Handler from 'aws-lambda';
import createConnection, Connection from 'mysql';
export const index: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) =>
let connection = createConnection(
host: process.env["DB_RO_HOST"],
user: process.env["DB_RO_USERNAME"],
password: process.env["DB_RO_PASSWORD"],
database: process.env["DB_RO_NAME"]
);
connection.connect();
const response =
statusCode: 200,
body: JSON.stringify("\"test\":\"test\""),
;
cb(null, response);
当我尝试调用 connect() 方法时出现代码错误。
我的研究导致一些人说要在旧版本的 Uglify 和 Webpack 中关闭 Uglify 中的 mangle。然而,我正在运行一个现代 webpack。
我的 package.json
"name": "aws-nodejs-typescript",
"version": "1.0.0",
"description": "Serverless webpack example using Typescript",
"main": "handler.js",
"scripts":
"test": "echo \"Error: no test specified\" && exit 1"
,
"dependencies":
"source-map-support": "^0.5.0"
,
"devDependencies":
"@types/aws-lambda": "8.10.1",
"@types/mysql": "^2.15.5",
"@types/node": "^8.10.21",
"mysql": "^2.16.0",
"serverless-webpack": "^5.1.1",
"ts-loader": "^4.2.0",
"typescript": "^2.8.1",
"webpack": "^4.5.0"
,
"author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)",
"license": "MIT"
【问题讨论】:
我已将 webpackmode
从 production
更改为 development
并且错误消失了,我认为这不是解决方案,但至少我可以继续
我也想这样做,但我正在使用 nuxt。设置NODE_ENV=development
没有帮助。我总是收到此错误Error: Received packet in the wrong sequence.
还有其他想法吗?
【参考方案1】:
已知此错误:NodeJs API + Webpack 2 Production Builds = Error: Received packet in the wrong sequence
解释见此贴:"Error: Received packet in the wrong sequence." when connect to serverless aurora
您可以通过卸载mysql并安装mysql2来修复它,mysql2可以使用promises
【讨论】:
以上是关于无服务器框架、打字稿、nodejs 和 mysql - 错误:接收到的数据包顺序错误的主要内容,如果未能解决你的问题,请参考以下文章