Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vedtam opened this issue Oct 15, 2016 · 12 comments

Comments

@vedtam
Copy link

vedtam commented Oct 15, 2016

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;
  }
@vedtam vedtam changed the title Uncaught Error: Received packet in the wrong sequence - using the following webpack production settings "Uncaught Error: Received packet in the wrong sequence" with devtools off - Electron + MySQL node driver + Webpack Oct 16, 2016
@dougwilson
Copy link
Member

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?

@vedtam
Copy link
Author

vedtam commented Oct 20, 2016

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.

@dougwilson
Copy link
Member

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).

@vedtam
Copy link
Author

vedtam commented Oct 20, 2016

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

@dougwilson
Copy link
Member

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

@dougwilson
Copy link
Member

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!

@akleiber
Copy link

@dougwilson
Copy link
Member

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!

@akleiber
Copy link

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.

@wenisy
Copy link

wenisy commented Oct 19, 2017

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

I saw a solution here #1655 , hope it could help you.
Change UglifyJsPlugin mangle: false

@akleiber
Copy link

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

@eldhotkuriakose
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants