5

I get the following error when trying to start my server.js which requires the module "userid".

  module.js:460
  return process.dlopen(module, path._makeLong(filename));
                 ^

Error: Module version mismatch. Expected 46, got 47.
    at Error (native)
    at Object.Module._extensions..node (module.js:460:18)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/root/backend/node_modules/userid/lib/userid.js:2:15)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)

How can I solve this issue?

Kevin Keller
  • 61
  • 3
  • 6
  • I was recently experiencing this error and solved it (for my case at least). Mine seemed to stem originally from the gRPC and bindings modules. What OS are you running? In my case I was using Linux (Ubuntu) and the real issue had to do with NPM and the combination of Node (NVM installed) and Nodejs (Ubuntu's APT repo installed). – Brandon K Feb 03 '16 at 15:12
  • Follow-up to my own previous comment: encountered the issue again. I had used NVM previously to install Node and later on used apt to install nodejs (bad idea). Tried many things without success, finally purged system of node and nodejs; removed the .nvm dir from home. Edited .bashrc to remove export of nvm's node bin from PATH, removed entire /usr/local/lib/node_modules dir. Then installed nodejs using [this link](http://askubuntu.com/questions/594656/how-to-install-the-latest-versions-of-nodejs-and-npm-for-ubuntu-14-04-lts) for version 5.x in my case. Finally used npm to upgrade npm > 3.0 – Brandon K Mar 07 '16 at 16:01
  • Mine was because of an import which was not specified in the package.json, but was installed by another module. – ATOzTOA Mar 09 '16 at 22:02

3 Answers3

3

Not sure of the exact meaning of this error but my fix for this is to delete the node_modules directory and reinstall the required modules with npm install.

The above is a solution for this error showing up in a node project which uses locally installed modules. If there are some global modules that are throwing this error then you might have to reinstall those.

datUser
  • 287
  • 7
  • 20
1

I would try upgrading the module version that causes the issue on package.json.

Fintan Kearney
  • 743
  • 7
  • 15
0

Another reason of this problem is that you have several different node versions installed at your system and you manage them with nvm. If you run node index.js and if you run sudo node index.js it may results in running different node version.

So if you installed your application modules with npm install and then run application with sudo node index.js you will have Module version mismatch error. In such case make sure with nvm that sudo node... run the same version of node as your application expects.

Also, while fixing initial problem you may have problem with nvm described here Can't use NVM from root (or sudo). One of possible solutions to this issue described in Yoo Matsuo's comment.

Serg
  • 2,346
  • 3
  • 29
  • 38