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

其他回答

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

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)

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

npm rebuild bcrypt --update-binary

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

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

我来这里是因为我在vscode中得到这个关于quokka.js ext的错误。

我的解决方案: (在MAC上通过终端)

1-我去~/.quokka

2-我运行nano config.json

3-我从配置中复制了代码。Json放到一个单独的文件中

4-我删除了config.json中的代码

5-我停下来,重新启动短尾矮袋鼠。

6-一旦我确认短尾矮袋鼠工作没有错误,我删除配置。Json文件代码。

简单地运行:

NPM卸载bcrypt

紧随其后的是:

NPM install bcrypt(或者NPM install,如果bcrypt在你的包中被声明为依赖项)。json文件)

以下是对我有效的方法。我使用循环节点模块与电子Js和面临这个问题。在尝试了很多事情之后,以下的工作对我来说。

在你的包裹里。Json文件在脚本中添加以下行:

  ... 
"scripts": {
        "start": "electron .",
        "rebuild": "electron-rebuild"
    
      },
...

然后运行以下命令npm run rebuild