Node - 使用 NODE_MODULE_VERSION 51 针对不同的 Node.js 版本编译

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46384591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:29:50  来源:igfitidea点击:

Node - was compiled against a different Node.js version using NODE_MODULE_VERSION 51

node.jsnpmversionnode-modules

提问by JoeTidee

I am running a node application on terminal. Have recently upgraded to node v8.5.0, but am getting this error:

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

Any idea how to solve this?

知道如何解决这个问题吗?

回答by alexmac

You need to remove the module folder (bcrypt) from the node_modulesfolder and reinstall it, use the following commands:

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

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

回答by chitzui

I had the same problem and nothingmentioned here worked for me. Here is what worked for me:

我遇到了同样的问题,这里提到的任何内容都不适合我。这是对我有用的:

  1. Require all dependencies you need in the main.jsfile that is run by electron. (this seemed to be the first important part for me)
  2. Run npm i -D electron-rebuildto add the electron-rebuildpackage
  3. Remove the node-modulesfolder, as well as the packages-lock.jsonfile.
  4. Run npm ito install all modules.
  5. Run ./node_modules/.bin/electron-rebuild(.\node_modules\.bin\electron-rebuild.cmdfor Windows) to rebuild everything
  1. main.js由电子运行的文件中需要您需要的所有依赖项。(这对我来说似乎是第一个重要的部分)
  2. 运行npm i -D electron-rebuild添加电子重建
  3. 删除node-modules文件夹以及packages-lock.json文件。
  4. 运行npm i以安装所有模块。
  5. 运行./node_modules/.bin/electron-rebuild.\node_modules\.bin\electron-rebuild.cmd对于 Windows)以重建所有内容

It is very importantto run ./node_modules/.bin/electron-rebuilddirectly after npm iotherwise it did not work on my mac.

这是非常重要的运行./node_modules/.bin/electron-rebuild后直接npm i否则就没有我的Mac上运行。

I hope I could help some frustrated souls.

我希望我能帮助一些沮丧的灵魂。

回答by RPichioli

You have to rebuild the packageand tell npm to update it's binary too. Try:

你必须重建包告诉 npm 更新它的二进制文件。尝试:

npm rebuild bcrypt --update-binary

@robertklep answered a relative question with this command, look.

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

Only rebuild haven't solved my problem, this works fine in my application.

只有重建并没有解决我的问题,这在我的应用程序中运行良好。

Hope it helps!

希望能帮助到你!

回答by Frosty Z

Simply run:

只需运行:

npm uninstall bcrypt

npm uninstall bcrypt

Followed by:

其次是:

npm install bcrypt(or npm install, if bcryptis declared as dependency in your package.jsonfile)

npm install bcrypt(或者npm install,如果bcrypt在您的package.json文件中被声明为依赖项)

回答by smets.kevin

Most likely you have this issue due to the package-lock.json. Somehow it seems to block you from recompiling or rebuilding your dependencies, even if you explicitly run npm rebuild. I ran all the following to fix it for me:

由于 package-lock.json,您很可能会遇到此问题。不知何故,它似​​乎阻止您重新编译或重建您的依赖项,即使您明确运行npm rebuild. 我运行了以下所有内容来为我修复它:

rm package-lock.json;
rm -rf node_modules;
npm install;

回答by liming gao

you can see this link

你可以看到这个链接

to check your node verison right. using NODE_MODULE_VERSION 51 means that your node version is nodejs v7.x, requires NODE_MODULE_VERSION 57 means you need upgrade your node to v8.x,so you need to upgrade your node. and then you need run npm rebuildcommand to rebuild your project

检查您的节点版本是否正确。使用 NODE_MODULE_VERSION 51 意味着你的节点版本是 nodejs v7.x,需要 NODE_MODULE_VERSION 57 意味着你需要升级你的节点到 v8.x,所以你需要升级你的节点。然后你需要运行npm rebuild命令来重建你的项目

回答by Barkles

Be sure you only have one version of NodeJS installed. Try these two:

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

node --version
sudo node --version

I initially installed NodeJS from source, but it was the incorrect version and 'upgraded' to the newest version using nvm, which doesn't remove any previous versions, and only installs the desired version in the /root/.nvm/versions/...directory. So sudo nodewas still pointing to the previous version, whilst nodewas pointing to the newer version.

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

回答by Matt

I got the same error but I was trying to run a node application using a Docker container.

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

I fixed it by adding a .dockerignore file to ignore the node_modules directory to make sure that when the docker image builds, it builds the native packages for the image I wanted (Alpine) instead of copying over the node_modules compiled for my host (Debian).

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

回答by Craig Odell

Turns out my problem was user-error: make sure the version of node you are using for running is the same that you are using when running an npm install or yarn.

原来我的问题是用户错误:确保您用于运行的节点版本与您在运行 npm install 或 yarn 时使用的版本相同。

I use NVM for versioning node and was running yarn via a terminal, but my IDE was set to use an older version of node when running and it was throwing the error above. Matching my IDE's version of node in the run config to node --version fixed the issue.

我使用 NVM 进行节点版本控制,并通过终端运行 yarn,但我的 IDE 在运行时设置为使用旧版本的节点,并且抛出上述错误。将运行配置中我的 IDE 节点版本与节点 --version 匹配解决了该问题。

回答by tomm1e

For Electron modules, install electron-rebuild.

对于 Electron 模块,安装 electron-rebuild。

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

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

Specify the same version that you have installed in the current directory

指定与您在当前目录中安装的相同版本

You might have this experience where a standard node-gyp build would report as 64, then a basic electron-rebuild would report 76, not until you add -v with exact version it bumps to actual version 80 (for 9.0.0-beta.6)

您可能有这样的经历:标准 node-gyp 构建报告为 64,然后基本电子重建报告为 76,直到您添加 -v 与确切版本,它会碰撞到实际版本 80(对于 9.0.0-beta. 6)