3

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

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.

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:

...

 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>

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;
  }
Edmond Tamas
  • 3,148
  • 9
  • 44
  • 89

1 Answers1

0

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:

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"
  },

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!

Nebulosar
  • 1,727
  • 3
  • 20
  • 46
  • Yeah, this is something related with optimization, Iam using ERB electron react boilterplate, having the same issue – Frank Guo Dec 26 '21 at 05:51