Node - was compiled against a different Node.js ve

2020-01-24 11:17发布

I am running a node application on terminal. Have recently upgraded to node v8.5.0, but am getting this error:

Error: The module '/tidee/tidee-au/packages/tidee-au-server/node_modules/bcrypt/lib/binding/bcrypt_lib.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 51. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (module.js:653:18)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/tidee/tidee-au/packages/tidee-au-server/node_modules/bcrypt/bcrypt.js:6:16)
    at Module._compile (module.js:624:30)
    at Module._extensions..js (module.js:635:10)
    at Object.require.extensions.(anonymous function) [as .js] (/tidee/tidee-au/packages/tidee-au-server/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/tidee/tidee-au/packages/tidee-au-server/server/helpers/encryptPass.js:1:16)

Any idea how to solve this?

24条回答
时光不老,我们不散
2楼-- · 2020-01-24 11:41

you can see this link

to check your node verison right. using NODE_MODULE_VERSION 51 means that your node version is nodejs v7.x, requires NODE_MODULE_VERSION 57 means you need upgrade your node to v8.x,so you need to upgrade your node. and then you need run npm rebuild command to rebuild your project

查看更多
Juvenile、少年°
3楼-- · 2020-01-24 11:42

Be sure you only have one version of NodeJS installed. Try these two:

node --version
sudo node --version

I initially installed NodeJS from source, but it was the incorrect version and 'upgraded' to the newest version using nvm, which doesn't remove any previous versions, and only installs the desired version in the /root/.nvm/versions/... directory. So sudo node was still pointing to the previous version, whilst node was pointing to the newer version.

查看更多
祖国的老花朵
4楼-- · 2020-01-24 11:42

You could remove bcrypt entirely and install bcryptjs. It is ~30% slower, but has no dependencies, so no pains installing it.

npm i -S bcryptjs && npm uninstall -S bcrypt

We've installed it successfully for our applications. We had issues with bcrypt not compiling on AWS instances for Node v8.x

查看更多
beautiful°
5楼-- · 2020-01-24 11:44

I got this error when running my app with systemd:

ExecStart=/usr/local/bin/node /srv/myapp/server.js

But I was using a different version for npm install in the shell:

$ which node
/home/keith/.nvm/versions/node/v8.9.0/bin/node

If this is your setup, you can either hardcode the node version in the service file or follow a workaround like this one.

查看更多
Root(大扎)
6楼-- · 2020-01-24 11:46

Check the Node version you're using, might be a mismatch between what it is expected.

查看更多
神经病院院长
7楼-- · 2020-01-24 11:48

Simply run:

npm uninstall bcrypt

Followed by:

npm install bcrypt (or npm install, if bcrypt is declared as dependency in your package.json file)

查看更多
登录 后发表回答