Error: Loading non-context-aware native module in renderer: @serialport\bindings\build\Release\bindings.node'

Viewed 1363

I am new to electron and serialport. I started a simple node project, just installed electron and serialport, everything is fine, but when i use let serialport = require('serialport') it gives the above error. I didn't use even a second line of code in javascript in index.html page. I have tried and searched its solution many times, but couldn't find it. I have even read its cause at https://github.com/electron/electron/issues/18397

"dependencies": {
    "electron": "^9.2.0",
    "serialport": "^9.0.1"
  }

if i use
app.allowRendererProcessReuse = false
it gives following error

Uncaught Error: The module '\\?\D:\newutkal\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 80. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

I also tried npm install But same error. Please explain its solution in simple steps(in coding terms if possible). Thanks for having attention on this topic. :)

1 Answers

as written in serialport docs in electron guide-installation:

  1. Run npm install --save-dev electron-rebuild

2.Add electron-rebuild to your project's package.json's install hook

3.Run npm install

If you have trouble on Windows, try: .\node_modules.bin\electron-rebuild.cmd

Related