我正在终端上运行一个节点应用程序。最近已经升级到节点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.

其他回答

我在grpc模块中遇到了同样的问题,在我的情况下,我正在使用电子,并在env变量“export npm_config_target=1.2.3”中设置了错误的电子版本,将其设置为我正在使用的电子版本,解决了我的问题。希望这能帮助那些设置env变量的人(https://electronjs.org/docs/tutorial/using-native-node-modules#the-npm-way)

我刚刚得到这个错误运行kadence安装的“kadence”脚本首先检查nodejs,如果没有nodejs只运行node。我把最新版本的node链接到我的~/bin目录中,但nodejs运行的是一个我忘记卸载的旧版本,但直到现在才出现问题。

所以有这个问题的人可能会检查node和nodejs是否实际运行相同版本的node…

你只需要运行下面的命令:

$ rm -rf node_modules
$ rm -rf yarn.lock
$ yarn install

最后

$ ./node_modules/.bin/electron-rebuild

不要忘记yarn添加电子重建,如果它不存在于你的依赖。

你可以看到这个链接

检查节点版本是否正确。使用 NODE_MODULE_VERSION 51表示节点版本为nodejs v7。NODE_MODULE_VERSION 57意味着您需要将节点升级到v8。X,你需要升级你的节点。然后你需要运行NPM rebuild命令来重建你的项目

您可以完全删除bcrypt并安装bcryptjs。它慢了大约30%,但是没有依赖,所以安装它并不痛苦。

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

我们已经成功地为我们的应用程序安装了它。我们遇到了bcrypt无法在Node v8.x的AWS实例上编译的问题