問題描述
當我使用 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
設置為 ''
時崩潰??我?guī)缀跽也坏筋愃频膱蟾妫挥形矣羞@個問題嗎?
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!
這篇關于“未捕獲的錯誤:接收到的數(shù)據(jù)包順序錯誤"關閉 devtools - Electron + MySQL 節(jié)點驅動程序 + Webpack的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!