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

知道怎么解决吗?


当前回答

在我的例子中,我运行的是nodejs而不是node。由于nodejs是由包管理器安装的:

# which node
/home/user/.nvm/versions/node/v11.6.0/bin/node

# which nodejs
/usr/bin/nodejs

其他回答

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

$ rm -rf node_modules/bcrypt

然后重新安装

$ npm install

你可以开始了。好吧

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

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

最后

$ ./node_modules/.bin/electron-rebuild

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

您需要从node_modules文件夹中删除模块文件夹(bcrypt)并重新安装,使用以下命令:

$ rm -rf node_modules/bcrypt
$ npm install
// or
$ yarn

你可以看到这个链接

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

对于电子模块,安装电子重建。

Format:
electron-rebuild -o <module_name> -v <electron version>

Example:
electron-rebuild -o myaddon -v 9.0.0-beta.6

指定当前目录中已安装的相同版本

你可能有这样的经验,一个标准的node-gyp构建将报告为64,然后一个基本的电子重建将报告76,直到你添加-v与确切的版本,它会颠簸到实际的版本80 (9.0.0-beta.6)