我是 Electron 和串口的新手。我开始了一个简单的 Node 项目,只安装了 electron 和 serialport,一切都很好,但是当我使用 let serialport = require('serialport')
时,它给出了上述错误。我什至没有在 index.html 页面的 javascript 中使用第二行代码。
我已经尝试并多次搜索其解决方案,但找不到。
我什至在 https://github.com/electron/electron/issues/18397 阅读了它的原因
"dependencies": {
"electron": "^9.2.0",
"serialport": "^9.0.1"
}
如果我用
app.allowRendererProcessReuse = false
它给出以下错误
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`).
我也试过 npm install
但同样的错误。
请用简单的步骤解释它的解决方案(如果可能的话用编码术语)。
感谢您关注这个话题。 :)
最佳答案
如 electron guide-installation 中的串口文档中所写:
- 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
关于javascript - 错误 : Loading non-context-aware native module in renderer: @serialport\bindings\build\Release\bindings. Node ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63377030/