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

知道怎么解决吗?


当前回答

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

其他回答

你必须重新构建包,并告诉npm更新它也是二进制的。试一试:

npm rebuild bcrypt --update-binary

@robertklep用这个命令回答了一个相关的问题,看。

只有重建还没有解决我的问题,这在我的应用程序工作得很好。

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

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)

检查您正在使用的Node版本,可能与预期的不匹配。

我得到了同样的错误,但我试图运行一个节点应用程序使用Docker容器。

我通过添加一个.dockerignore文件来忽略node_modules目录来修复它,以确保当构建docker映像时,它为我想要的映像(Alpine)构建本机包,而不是复制为我的主机(Debian)编译的node_modules。

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

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