node.js 模块版本不匹配。预期 11,得到 1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15584529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Module version mismatch. Expected 11, got 1
提问by Alfred
Platform: Linux
When running my node.js program I got the following error
运行我的 node.js 程序时出现以下错误
Error: Module version mismatch. Expected 11, got 1.
回答by hisland
you might give the error like this:
你可能会给出这样的错误:
Error: Module version mismatch. Expected 11, got 1.
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/user/node_modules/xml2json/node_modules/node-expat/lib/node-expat.js:4:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
and then, you can notice the error in module or somewhere.
然后,您可以注意到模块或某处的错误。
this is because you have updated your node, you might rebuild the module found above.
这是因为您已经更新了您的节点,您可能会重建上面找到的模块。
i revole my question by reinstall(remove, then install) xml2json.
我通过重新安装(删除,然后安装)xml2json 来解决我的问题。
good luck!
祝你好运!
回答by menzoic
回答by Alfred
Platform: Linux
For future reference in node.js v0.10.x(at least v0.10.0) I got this error:
为了将来在node.js v0.10.x(至少v0.10.0)中参考,我收到了这个错误:
Error: Module version mismatch. Expected 11, got 1.
To fix this I found this interesting linkand also had some help from Ben Noordhuis. The following command helped me get rid of this error:
为了解决这个问题,我发现了这个有趣的链接,并且还得到了Ben Noordhuis 的一些帮助。以下命令帮助我摆脱了这个错误:
npm update
回答by robbrit
This usually happens when you install a package using one version of Node, then change to a different version. This can happen when you update Node, or switch to a different version with nvm.
这通常发生在您使用一个版本的 Node 安装软件包,然后更改为其他版本时。当您更新 Node 或使用 nvm 切换到不同版本时,可能会发生这种情况。
It can also happen if you're trying to run a process as root with a globally installed Node, but you're running an nvm-managed node within your own user account.
如果您尝试使用全局安装的 Node 以 root 身份运行进程,但您在自己的用户帐户中运行 nvm 管理的节点,也会发生这种情况。
To fix this, you can simply re-install the packages using the correct version of Node. Also ensure that you're using the same version of Node across the different users.
要解决此问题,您只需使用正确版本的 Node.js 重新安装软件包即可。还要确保您在不同用户之间使用相同版本的 Node。
回答by hqt
This problem is happened because following scenario: you are using Node for example version 5. You add some libraries inside your project, build and run that. All your libraries will be compiled under node version 5.
发生此问题是因为以下场景:例如,您使用的是 Node 版本 5。您在项目中添加了一些库,构建并运行它。您的所有库都将在节点版本 5 下编译。
And then you upgrade your node for example to version 6. And then you run some commands that using node, for example npm run test. The problem is here: you use newer node version for running libraries that compiled by older node.
然后你将你的节点升级到版本 6。然后你运行一些使用节点的命令,例如npm run test. 问题在这里:您使用较新的节点版本来运行由较旧节点编译的库。
Solving this is easy by 2 following commands:
通过以下 2 个命令可以轻松解决此问题:
rm -rf node_modules // force remove node_modules directory
npm install // install again all libraries.
回答by jamesthe500
One more thing to try if you're using nvm- make sure you are running the same version of node globally as well as within the app.
如果您使用 nvm,还要尝试另一件事 - 确保您在全局以及应用程序中运行相同版本的节点。
:/$ node -v
v6.0.0
:/var/www/app$ node -v
v6.2.0
If they aren't in agreement:
如果他们不同意:
:/$ nvm use 6.2.0
Now using node v6.2.0 (npm v3.8.9)
(This is what worked for me.)
(这对我有用。)
回答by Thomas Welton
You can find a list of node module versions and their corresponding node release on this page https://nodejs.org/en/download/releases/
您可以在此页面上找到节点模块版本及其相应节点版本的列表https://nodejs.org/en/download/releases/
NODE_MODULE_VERSION refers to the ABI (application binary interface) version number of Node.js, used to determine which versions of Node.js compiled C++ add-on binaries can be loaded in to without needing to be re-compiled. It used to be stored as hex value in earlier versions, but is now represented as an integer.
NODE_MODULE_VERSION 是指 Node.js 的 ABI(应用程序二进制接口)版本号,用于确定 Node.js 编译的 C++ 附加二进制文件可以加载到哪些版本中,而无需重新编译。它曾经在早期版本中存储为十六进制值,但现在表示为整数。
回答by techie95
回答by WillW
None of the answers worked for me, so here is my solution.
Error: Module version mismatch. Expected 48, got 51.
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
The 48 and 51 correspond to node versions as found on nodejs release page:
https://nodejs.org/en/download/releases/
没有一个答案对我有用,所以这是我的解决方案。
Error: Module version mismatch. Expected 48, got 51.
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
48 和 51 对应于 nodejs 发布页面上的节点版本:https://nodejs.org/en/download/releases/
So I installed nvm, a node version manager, and switched my node version to 48 (6.11.x) and then ran
rm -rf node_modules/and
npm install
所以我安装了 nvm,一个节点版本管理器,并将我的节点版本切换到 48(6.11.x),然后运行
rm -rf node_modules/并
npm install
My particular module, mcrypt, depended on c++ binaries, and the Node Module Version has a direct impact:
我的特定模块 mcrypt 依赖于 c++ 二进制文件,节点模块版本有直接影响:
NODE_MODULE_VERSION refers to the ABI (application binary interface) version number of Node.js, used to determine which versions of Node.js compiled C++ add-on binaries can be loaded in to without needing to be re-compiled. It used to be stored as hex value in earlier versions, but is now represented as an integer.
NODE_MODULE_VERSION 是指 Node.js 的 ABI(应用程序二进制接口)版本号,用于确定 Node.js 编译的 C++ 附加二进制文件可以加载到哪些版本中,而无需重新编译。它曾经在早期版本中存储为十六进制值,但现在表示为整数。
回答by Rambatino
The easiest way to get to where you need to be, after you've changed your node version is:
更改节点版本后,到达所需位置的最简单方法是:
rm -Rf node_modules/ && yarn && yarn start
rm -Rf node_modules/ && yarn && yarn start
Replace yarn startwith whatever the command is that you need to start your server.
替换yarn start为启动服务器所需的任何命令。

