节点模块版本不匹配:应为 50

Node Module Version Mismatch: Expected 50

我遇到过这个问题,在全新安装的 Node 和 npm 中,serial port 包无法加载,Hello World Electron 包中出现以下错误:

我在 Node 版本 6.6.0 和 NPM 版本 3.10.7 和 OS X 10.11.6.

我查看了我是否过时了,但是查看 this list,我找不到任何模块版本为 50 的东西。这是一个错误吗?

我试过npm rebuild,也尝试过删除模块并重新安装,但没有成功。

更新:即使当我 运行 node -v 它打印 v6.6.0,运行ning process.versions.node 在网络控制台中给我 v6.5.0.这是怎么回事?

这是 known issue which is caused by the serialport module using native code that is built for a different version of Node. You can read a bit more about addons here,如果您有兴趣;它们只是用 C/C++ 编写的模块,可以与 Node 交互,因此模块可以更轻松地与硬件交互。

那个issue提出的解决方案是这样的:

npm rebuild --runtime=electron --target=1.2.5 --disturl=https://atom.io/download/atom-shell --build-from-source

如果您尚未安装 electron-rebuild,这可能有助于确保重建过程正常进行:

npm install --save-dev electron-rebuild

even though when I run node -v it prints v6.6.0, running process.versions.node in the web console gives me v6.5.0. What's going on here?

Electron 使用自己的 Node 版本,该版本未连接到您的系统 Node 安装(请参阅 homepage 查看最新 Electron 使用的 Node 版本,或使用 process.versions.node,例如你在问题中做到了)。

您可以尝试旧版本(也许 1.1.0,它使用 Chrome 50?)以防这是问题的原因。

在我的例子中,错误是:

App threw an error during load
Error: Module version mismatch. Expected 50, got 48.
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:583:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/myapp/node_modules/sqlite3/lib/sqlite3.js:4:15)

修复重建错误后:

npm install --save-dev electron-rebuild

npm rebuild --runtime=electron --target=1.4.3 --disturl=https://atom.io/download/atom-shell --build-from-source