模块版本不匹配。预期49,得到48

Module version mismatch. Expected 49, got 48

我正在使用 Electron 模块 mdns,但出现此错误

A JavaScript error occurred in the main process
Uncaught Exception:
Error: Module version mismatch. Expected 49, got 48.
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:167:20)
    at Object.Module._extensions..node (module.js:568:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:167:20)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/ingsaurabh/dp/node_modules/mdns/lib/dns_sd.js:24:20)

已卸载节点模块并重新安装,但无法正常工作

由于 mdns 包含本机 Node 模块,您必须重建它以针对您的 Electron 版本,因此有 a couple of ways to do this。我建议使用 electron-rebuild 方法。

升级节点版本时,这是众所周知的问题。例如:您正在使用 Node,例如版本 5。您在项目中添加了一些库,构建并 运行。您所有的库都将在节点版本 5 下编译。

然后将节点升级到版本 6。然后 运行 使用节点的一些命令,例如 npm 运行 test。问题出在这里:您对由旧节点编译的 运行ning 库使用较新的节点版本。

通过以下 2 个命令轻松解决此问题:

rm -rf node_modules // force remove node_modules directory
npm install         // install again all libraries. Libraries will be compiled again with node version 6

所以这是适用于所有 javascript 框架的通用方法,不仅 electron ...

npm rebuild --runtime=electron --target=1.3.4 --disturl=https://atom.io/download/atom-shell --abi=50

你的情况应该是 49