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:49

You need to remove the module folder (bcrypt) from the node_modules folder and reinstall it, use the following commands:

$ rm -rf node_modules/bcrypt
$ npm install
// or
$ yarn
查看更多
Emotional °昔
3楼-- · 2020-01-24 11:49

You have to rebuild the package and tell npm to update it's binary too. Try:

npm rebuild bcrypt --update-binary

@robertklep answered a relative question with this command, look.

Only rebuild haven't solved my problem, this works fine in my application.

Hope it helps!

查看更多
Bombasti
4楼-- · 2020-01-24 11:49

After trying different things. This worked.

Delete your node modules folder and run

npm i
查看更多
再贱就再见
5楼-- · 2020-01-24 11:49

I have hit this error twice in an electron app and it turned out the problem was that some modules need to be used from the main process rather than the render process. The error occurred using pdf2json and also node-canvas. Moving the code that required those modules from index.htm (the render process) to main.js (the main process) fixed the error and the app rebuilt and ran perfectly. This will not fix the problem in all cases but it is the first thing to check if you are writing an electron app and run into this error.

查看更多
做个烂人
6楼-- · 2020-01-24 11:50

I had the same problem and none of these solutions worked and I don't know why, they worked for me in the past for similar problems.

Anyway to solve the problem I've just manually rebuild the package using node-pre-gyp

cd node_modules/bcrypt
node-pre-gyp rebuild

And everything worked as expected.

Hope this helps

查看更多
Luminary・发光体
7楼-- · 2020-01-24 11:51

Turns out my problem was user-error: make sure the version of node you are using for running is the same that you are using when running an npm install or yarn.

I use NVM for versioning node and was running yarn via a terminal, but my IDE was set to use an older version of node when running and it was throwing the error above. Matching my IDE's version of node in the run config to node --version fixed the issue.

查看更多
登录 后发表回答