Mysql: "Uncaught Error: Received packet in the wrong sequence" with devtools off - Electron + MySQL node driver + Webpack

Created on 15 Oct 2016  路  12Comments  路  Source: mysqljs/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

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;
  }
help wanted

Most helpful comment

Hi,

The last couple days I have made some further testing. What I have realized is that if the MySQLjs module goes trough Webpack (used to bundle up dependencies), it won't survive.

How I got to this conclusion: first I have placed the myslqjs module import into my home.js file (renderer process) and not the main process (index.js), because I needed a single query in my app, and I wanted to skip Inter Process Communication for this simple task.

When I bundle up my app using Webpack, everything that is not inside the main process (index.js) get moved into the single bundle.js file including the content of home.js. With the option devtools = '', webpack disables source maps in the production build, while in dev mode it uses devtools = '#eval-source-map" which executes all modules (including mysqlj) via eval(), this evaluates the result of the module and I guess it surpresses warnings like the above mentioned.

The point is that there is a glitch in Webpack + mysqlj when queries are made in the renderer process. I would gladly help to find a fix for this, if you want.

All 12 comments

Hm. I have never used any of those tools, so would have no idea why you would need config.devtools = 'eval' or what that even does. I'm not sure what to really do. Perhaps if there is something we could do, would you be willing to put together a pull request?

Hi,

The last couple days I have made some further testing. What I have realized is that if the MySQLjs module goes trough Webpack (used to bundle up dependencies), it won't survive.

How I got to this conclusion: first I have placed the myslqjs module import into my home.js file (renderer process) and not the main process (index.js), because I needed a single query in my app, and I wanted to skip Inter Process Communication for this simple task.

When I bundle up my app using Webpack, everything that is not inside the main process (index.js) get moved into the single bundle.js file including the content of home.js. With the option devtools = '', webpack disables source maps in the production build, while in dev mode it uses devtools = '#eval-source-map" which executes all modules (including mysqlj) via eval(), this evaluates the result of the module and I guess it surpresses warnings like the above mentioned.

The point is that there is a glitch in Webpack + mysqlj when queries are made in the renderer process. I would gladly help to find a fix for this, if you want.

Sure! I have never used webpack, so simply unfamiliar. A PR with a fix will be very helpful to others experiencing the same issue (though you're the first to report that I know of).

I was inspecting the issue, placing some brakepoints, etc., but so far didn't find a clue.

Till than please try this, I have put together a working example, details you will find in the README file:
https://github.com/vedtam/electron-webpack-mysqlj

Thanks, @vedtam ! I can take a look at this in a few weeks if no one else gets to it before me :)

Hi @vedtam I'm sorry I never got around to this. I just went to look at your repo and it seems like it's gone. I'm not sure if I can really do anything, so especially without that repo any longer, I'm going to close this issue. If you can even provide a PR to fix this, that would be great!

Hi @akleiber do you think this is something that can be fixed here? If you can even provide a PR to fix this, that would be great!

Hi @dougwilson - I have no clue what line of code in mysqljs causes the issue - just wanted to drop this here in case somebody needs a quickfix.

@akleiber I met the same issue, have you solved this problem?

I saw a solution here https://github.com/mysqljs/mysql/issues/1655 , hope it could help you.
Change UglifyJsPlugin mangle: false

@wenisy yes - this is the solution we use currently - thx for clarification :-)

I have faced the same problem when bundling with web pack. at last i have solved the issue.
i think it is an issue related to web-pack and babel-loader version mismatch.
i suggest following combinations in package.json
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"mysql": "^2.15.0",
"serverless-webpack": "^2.2.3",
"webpack": "^3.5.5"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rhapsody-Sky picture Rhapsody-Sky  路  3Comments

hohozhao picture hohozhao  路  4Comments

winzig picture winzig  路  4Comments

johnrc picture johnrc  路  3Comments

skilbjo picture skilbjo  路  3Comments