问题描述
当我使用 Electron + Webpack + node MySQL 建立一个新项目时,我的生产版本是投掷:
When I set up a new project using Electron + Webpack + node MySQL my production build is throwing:
Uncaught Error: Received packet in the wrong sequence
只有当我在我的生产版本中保留:config.devtools = 'eval'
时,错误才会消失,显然这会导致更大的文件大小和一些我想避免的性能问题.
The error goes away only if I keep: config.devtools = 'eval'
in my production builds, apparently this will result in a larger file size and some performance issues which I would like to avoid.
为什么我的项目/mysql 模块在 devtools
设置为 ''
时崩溃??我几乎找不到类似的报告,只有我有这个问题吗?
Why my project / mysql module crashes with devtools
set to ''
?? I can hardly find similar reports, am I the only one having this issue?
webpack.config.js:
webpack.config.js:
...
if (process.env.NODE_ENV === 'production') {
config.devtool = '' // <-------- mysql will throw Uncaught Error if I omit 'eval'
config.plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
)
}
home.js:
<script>
var mysql = require('mysql')
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'password',
database: 'EONIC'
})
connection.connect()
connection.query('SELECT * from products', function (err, rows, fields) {
if (err) throw err <---- here will the error happen
console.log(rows)
})
connection.end()
</script>
mysql/lib/protocol/Protocol.js 中第 272 行的错误来源:
source of the error in mysql/lib/protocol/Protocol.js at line 272:
if (!sequence[packetName]) {
var err = new Error('Received packet in the wrong sequence.');
err.code = 'PROTOCOL_INCORRECT_PACKET_SEQUENCE';
err.fatal = true;
this._delegateError(err);
return;
}
推荐答案
这可能与 Webpack 的默认最小化器中的 mangle
选项与 Node 的 Mysql 包结合使用有关.
It could have something to do with the mangle
option in the default minimizer of Webpack in combination with the Mysql package for node.
我遇到过相同和类似的问题,但无法真正指出它.
I've faced the same and similar issues without really being able to pin point it.
有很多与此问题相关的问题:
There are a lot of questions out there related to this issue:
- https://github.com/webpack/webpack/issues/3150
- https://github.com/Bajdzis/vscode-database/issues/78
- https://github.com/mysqljs/mysql/issues/1655
但我找到的最佳解决方案是:
But the best solution I've found is this:
optimization: {
minimizer: [new TerserPlugin({ terserOptions: { mangle: false } })] // mangle false else mysql blow ups with "PROTOCOL_INCORRECT_PACKET_SEQUENCE"
},
在mysql问题威胁中是Rudijs:https://github.com/mysqljs/mysql/issues/1655#issuecomment-484530654
It is of Rudijs in the mysql issue threat: https://github.com/mysqljs/mysql/issues/1655#issuecomment-484530654
希望能帮到你,点个赞吧!
Hope this helps, give me a shout!
这篇关于“未捕获的错误:接收到的数据包顺序错误"关闭 devtools - Electron + MySQL 节点驱动程序 + Webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!