javascript - 错误 : Loading non-context-aware native module in renderer: @serialport\bindings\build\Release\bindings. Node '

标签 javascript node.js electron serial-port node-modules

我是 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 中的串口文档中所写:

  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

关于javascript - 错误 : Loading non-context-aware native module in renderer: @serialport\bindings\build\Release\bindings. Node ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63377030/

相关文章:

javascript - 使用 jQuery 查找正确的选择器

javascript - 为什么对象 [ID] 没有方法 'Animate' ?

javascript - JS区分iPhone上的点击和滚动

javascript - 如何将选择选项插入对象数组中

javascript - Express.js - 在请求对象中通过主体转换接口(interface)

electron-packager:如何在 dist 中包含特定的 node_modules?

javascript - 这个书签如何运作

node.js - NodeJS 流 - 管道漏水?

javascript - 原子外壳中的关键事件

javascript - Electron 使用多个 js 脚本自动化 webview