問題描述
當(dāng)我使用 Electron + Webpack + node MySQL 建立一個(gè)新項(xiàng)目時(shí),我的生產(chǎn)版本是投擲:
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
只有當(dāng)我在我的生產(chǎn)版本中保留:config.devtools = 'eval'
時(shí),錯(cuò)誤才會(huì)消失,顯然這會(huì)導(dǎo)致更大的文件大小和一些我想避免的性能問題.
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.
為什么我的項(xiàng)目/mysql 模塊在 devtools
設(shè)置為 ''
時(shí)崩潰??我?guī)缀跽也坏筋愃频膱?bào)告,只有我有這個(gè)問題嗎?
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 行的錯(cuò)誤來(lái)源:
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 的默認(rèn)最小化器中的 mangle
選項(xiàng)與 Node 的 Mysql 包結(jié)合使用有關(guān).
It could have something to do with the mangle
option in the default minimizer of Webpack in combination with the Mysql package for node.
我遇到過相同和類似的問題,但無(wú)法真正指出它.
I've faced the same and similar issues without really being able to pin point it.
有很多與此問題相關(guān)的問題:
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
希望能幫到你,點(diǎn)個(gè)贊吧!
Hope this helps, give me a shout!
這篇關(guān)于“未捕獲的錯(cuò)誤:接收到的數(shù)據(jù)包順序錯(cuò)誤"關(guān)閉 devtools - Electron + MySQL 節(jié)點(diǎn)驅(qū)動(dòng)程序 + Webpack的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!