我正在终端上运行一个节点应用程序。最近已经升级到节点v8.5.0,但我得到这个错误:

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)

知道怎么解决吗?


当前回答

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.

其他回答

在我的情况下,我在我的办公室代理跳过了一些包裹。当我走出我的办公室代理,并试图做npm安装它工作。也许这对某些人有帮助。

但我花了好几个小时才确定是什么原因。

我遇到了同样的问题,这些解决方案都不起作用,我不知道为什么,它们在过去的类似问题上对我有效。

无论如何,为了解决这个问题,我只是使用node-pre-gyp手动重新构建包

cd node_modules/bcrypt
node-pre-gyp rebuild

一切都按照预期进行。

希望这能有所帮助

可能是节点JS版本不一致导致了这个问题。如文档中所述。一定要使用其中一个版本。例如,在Dockerfile中指定:

# Pull lts from docker registry
FROM node:8.12.0

# ...

这是因为您当前更改了您的node js版本, 只需在项目的终端中运行

$ rm -rf node_modules/bcrypt

然后重新安装

$ npm install

你可以开始了。好吧

确保你只安装了一个版本的NodeJS。试试这两个:

node --version
sudo node --version

我最初从源代码安装NodeJS,但它是不正确的版本,并使用nvm“升级”到最新版本,它不会删除任何以前的版本,只在/root/.nvm/versions/…目录中。所以sudo node仍然指向以前的版本,而node指向更新的版本。