serialport for electron NODE_MODULE_VERSION error and rebuild does not fix

4.2k views Asked by At

OS: win 10 Node.js : v12.18.3 electron: v10.1.1

print version from js program: process.versions.node 12.16.3 process.versions.modules 82

  1. install serialport by: npm install serialport

  2. npm start and get error:

Error: The module '\?\D:\node\Tester\node_modules@serialport\bindings\build\Release\bindings.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 72. This version of Node.js requires NODE_MODULE_VERSION 82. Please try re-compiling or re-installing the module (for instance, using npm rebuild or npm install).

  1. npm install --save-dev electron-rebuild .\node_modules.bin\electron-rebuild

Rebuild Complete

  1. npm start and the error again.

Error: The module '\?\D:\node\Tester\node_modules@serialport\bindings\build\Release\bindings.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 72. This version of Node.js requires NODE_MODULE_VERSION 82. Please try re-compiling or re-installing the module (for instance, using npm rebuild or npm install).

What should be noticed is, both v12.18.3 and 12.16.3 has NODE_MODULE_VERSION 72. and no version gets 82. I don't know where the '82' comes from. How can I sovle it? Thanks.

2

There are 2 answers

0
S.koll On BEST ANSWER

I had the same issue this morning. With over 5 hours of troubleshooting the only thing that worked for me was to downgrade electron-rebuild to v2.0.1. I am using node v14.9.0(latest), electron v10.1.1(latest), serialport v9.0.1(latest)

Looks like they have an issue open: https://github.com/electron/electron-rebuild/issues/404

0
Azzam Jihad Ulhaq On

i had the same problem. Finally, i can solve this with some steps. Here they are.

1. install electron-rebuild

npm install --save-dev electron-rebuild

2. Run some script

On MacOS, run this

./node_modules/.bin/electron-rebuild

On Windows, try:

.\node_modules\.bin\electron-rebuild.cmd

3. Add start script in package.json

"rebuild": "electron-rebuild -f -w serialport"

4. Rebuild the project

npm run rebuild

I hope it will help you. have a nice day.