无服务器框架,打字稿,nodejs和mysql-错误:接收到的数据包顺序错误 [英] serverless framework, typescript, nodejs and mysql - Error: Received packet in the wrong sequence
问题描述
当使用安装了
npm install --save-dev mysql
我得到以下错误并跟踪.
I get the following error and trace.
{
"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()方法时,代码错误.
The code errors when I attempt to call the connect() method.
我的研究结果导致一些人说要在旧版本的Uglify和Webpack中关闭Uglify中的mangle.但是,我正在运行一个现代的webpack.
My research has resulted has resulted in several people saying to turn mangle off in Uglify in older versions of Uglify and Webpack. I am however running a modern webpack.
我的package.json
My 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"
}
推荐答案
已知此错误: NodeJs API + Webpack 2生产版本=错误:接收到的数据包顺序错误
The explanation is shown in this post: "Error: Received packet in the wrong sequence." when connect to serverless aurora
您可以通过卸载 mysql 并安装 mysql2 来修复它,mysql2可以使用promises
You can fix it by uninstalling mysql and installing mysql2, mysql2 works with promises
这篇关于无服务器框架,打字稿,nodejs和mysql-错误:接收到的数据包顺序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!