45
Platform: Linux

When running my node.js program I got the following error

Error: Module version mismatch. Expected 11, got 1.
Alfred
  • 60,935
  • 33
  • 147
  • 186

14 Answers14

54

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.

good luck!

hisland
  • 669
  • 7
  • 8
  • 4
    To clarify: `npm uninstall xml2json` followed by again running `npm install` should do it. – elimisteve Nov 10 '13 at 21:33
  • 4
    I was struggling with this for the longest time and found that just doing `rm -fr node_modules && npm install` fixed it – Maruf Jun 04 '15 at 13:49
34

npm rebuild will also do the trick

https://www.npmjs.org/doc/cli/npm-rebuild.html

menzoic
  • 874
  • 1
  • 8
  • 10
19
Platform: Linux

For future reference in node.js v0.10.x(at least v0.10.0) I got this error:

Error: Module version mismatch. Expected 11, got 1.

To fix this I found this interesting link and also had some help from Ben Noordhuis. The following command helped me get rid of this error:

npm update
Alfred
  • 60,935
  • 33
  • 147
  • 186
11

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.

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.

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.

robbrit
  • 17,560
  • 4
  • 48
  • 68
4

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.

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.

Solving this is easy by 2 following commands:

rm -rf node_modules // force remove node_modules directory
npm install         // install again all libraries. 
hqt
  • 29,632
  • 51
  • 171
  • 250
3

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.

:/$ 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.)

jamesthe500
  • 341
  • 1
  • 7
  • 10
2

You can find a list of node module versions and their corresponding node release on this page 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.

Thomas Welton
  • 148
  • 1
  • 5
1

Sometimes the problem arises due to the nodejs version too.

Try updating the npm and nodejs version. Follow this link to update your nodejs.

And to update your npm use:

sudo npm install npm -g

Hope this helps!

techie95
  • 515
  • 3
  • 16
0

In my case the reason for the error was a C++-AddOn which was compiled against a different node.js Version.

So you might have to recompile your C++-AddOn, so the major versions of the addon and the node.js you run match.

A.Franzen
  • 725
  • 4
  • 10
  • 1
    Nobody mentioned C++ add-ons yet. And they do need to be compiled outside of node.js. With whatever compiler you use. – A.Franzen Aug 02 '16 at 13:52
0

I had this problem with systemd, but I could run the app using node myapp.js.

It turns out that the path in ExecStart differed from the one I got from which node. Changing that in the service file fixed it for me.

source

ki9
  • 5,183
  • 5
  • 37
  • 48
0

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/

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

My particular module, mcrypt, depended on c++ binaries, and the Node Module Version has a direct impact:

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.

WillW
  • 43
  • 6
0

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

Replace yarn start with whatever the command is that you need to start your server.

Rambatino
  • 4,716
  • 1
  • 33
  • 56
0

If the module is a c++ add-on, you may have to rebuild the node-gyp

node-gyp rebuild
0

None of the above answers solved the issue for me. The solution for me was to use xml2js instead of xml2json.

rycornell
  • 709
  • 6
  • 13