node.js GYP 错误!构建错误。堆栈错误:'make' 失败,退出代码为 2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44316064/
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
GYP ERR! build error. stack Error: 'make' failed with exit code 2
提问by Michael Vaquier
I am currently working on a nodejs web application I am having trouble pushing the application online with cloud foundry. I did some research on the errors and it seems that maybe some of the packages being installed have some conflicts.
我目前正在开发一个 nodejs Web 应用程序,但在使用 Cloud Foundry 在线推送应用程序时遇到了问题。我对错误进行了一些研究,似乎正在安装的某些软件包可能存在一些冲突。
This is the package.json file.
这是 package.json 文件。
{
"dependencies": {
"c3": "^0.4.12",
"cfenv": "1.0.0",
"cloudant": "^1.8.0",
"dygraphs": "^2.0.0",
"express": "4.5.1",
"getmac": "1.0.6",
"http": "0.0.0",
"mqtt": "1.0.5",
"properties": "1.2.1",
"save": "^2.3.0",
"sockjs": "0.3.9",
"websocket-multiplex": "0.1.x"
},
"description": "description.",
"license": "UNLICENSED",
"main": "app.js",
"repository": {
"type": "git",
"url": "<gitUrl>"
}
}
This is the error I encounter when I try to push the application via cloud foundry. This similar error happens when I npm install after deleting all the content of the node_modulesfolder.
这是我尝试通过云代工厂推送应用程序时遇到的错误。当我在删除node_modules文件夹的所有内容后进行 npm install 时,会发生类似的错误。
../src/bufferutil.cc:32:50: error: call of overloaded 'NODE_SET_METHOD(v8::Local<v8::FunctionTemplate>&, const char [6], void (&)(const v8::FunctionCallbackInfo<v8::Value>&))' is ambiguous
NODE_SET_METHOD(t, "merge", BufferUtil::Merge);
../src/bufferutil.cc:32:50: note: candidates are:
In file included from ../src/bufferutil.cc:8:0:
/root/.node-gyp/8.0.0/include/node/node.h:257:13: note: void node::NODE_SET_METHOD(v8::Local<v8::Template>, const char*, v8::FunctionCallback)
inline void NODE_SET_METHOD(v8::Local<v8::Template> recv,
^
/root/.node-gyp/8.0.0/include/node/node.h:270:13: note: void node::NODE_SET_METHOD(v8::Local<v8::Object>, const char*, v8::FunctionCallback)
inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
^
bufferutil.target.mk:95: recipe for target 'Release/obj.target/bufferutil/src/bufferutil.o' failed
make: *** [Release/obj.target/bufferutil/src/bufferutil.o] Error 1
make: Leaving directory '/home/WibiSmart-Bluemix-App/node_modules/bufferutil/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:285:23)
gyp ERR! stack at emitTwo (events.js:125:13)
gyp ERR! stack at ChildProcess.emit (events.js:213:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:197:12)
gyp ERR! System Linux 4.4.30-ti-r64
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/WibiSmart-Bluemix-App/node_modules/bufferutil
gyp ERR! node -v v8.0.0
gyp ERR! node-gyp -v v3.6.1
gyp ERR! not ok
Did anyone else encounter this issue, or knows how to fix it?
有没有其他人遇到过这个问题,或者知道如何解决?
采纳答案by Michael Vaquier
Figured out the issue. Some of the npm packages were not up to date. I modified the package.json to install all the latest versions of all packages and the error was fixed.
想通了这个问题。一些 npm 包不是最新的。我修改了 package.json 以安装所有包的所有最新版本,错误已修复。
回答by NuOne
It worked after deleting
package-lock.jsonand re runnpm installIf you are using yarn to build your program delete
yarn.lockand re runyarn install
删除
package-lock.json并重新运行后它起作用了npm install如果您使用纱线来构建您的程序,请删除
yarn.lock并重新运行yarn install
回答by andromeda
Delete the ~/.node-gyp folder and then the ~/.npmrc file.
删除 ~/.node-gyp 文件夹,然后删除 ~/.npmrc 文件。
Reboot your server and rerun npm install in your project folder
重新启动服务器并在项目文件夹中重新运行 npm install
Edit:
编辑:
Warning: removing ~/.npmrc will delete your other configurations
警告:删除 ~/.npmrc 将删除您的其他配置
回答by Ian Ellis
For other people that stumble into this exact problem:
对于偶然发现这个确切问题的其他人:
In my case, the server node version was set to an older version in my package.json file than what my local environment was running. So check what you are running locally with:
就我而言,我的 package.json 文件中的服务器节点版本设置为比我的本地环境运行的版本旧的版本。因此,请检查您在本地运行的内容:
node --version
-> 8.11.3
Then look at your server setting in your package.json:
然后查看 package.json 中的服务器设置:
{
"name": "myapp",
"version": "0.0.0",
"private": true,
"engines": {
"node": "7.10.2" // <-- This is too old, set it to the node version you are running locally (8.11.3)
},
I hope this helps someone.
我希望这可以帮助别人。
回答by piscator
In our case (since makefailed), this issue could be resolved by installing the build / development tools:
在我们的例子中(因为make失败),这个问题可以通过安装构建/开发工具来解决:
Ubuntu / Debian:
Ubuntu / Debian:
apt-get install -y build-essential
CentOS:
CentOS:
yum install gcc gcc-c++ make
Fedora 23 and above:
Fedora 23 及更高版本:
dnf install @development-tools
If this is not the solution, you might want to try to upgrade or downgrade node, remove package-lock.jsonand the node_modulesfolder, and then re-run npm install.
如果这不是解决办法,你可能想尝试升级或降级节点,删除package-lock.json和node_modules文件夹,然后重新运行npm install。
回答by Slartibartfast
This has been old yet consistent issue well documented at: https://github.com/nodejs/node-gyp/issues/809
这是一个古老而一致的问题,记录在案:https: //github.com/nodejs/node-gyp/issues/809
For me the error mentioned the version numbers like:
对我来说,错误提到了版本号,如:
gyp ERR! System Darwin 17.7.0
gyp ERR! node -v v12.1.0
gyp ERR! node-gyp -v v3.8.0
After attempting all the possible combinations of solutions (modify ~/.npmrc, remove ~/.node-gyp, clear the npm cache, delete node_modulesand even restart the system), what worked with me was downgrading the node.
在尝试了所有可能的解决方案组合(修改~/.npmrc、删除~/.node-gyp、清除 npm 缓存、删除node_modules甚至重新启动系统)后,对我有用的是降级节点。
I believe the versions mentioned in the log for nodeand node-gypare incompatible. So I reverted to an older node version which worked like a charm.
我相信日志中提到的版本node和node-gyp不兼容。所以我恢复到一个旧的节点版本,它就像一个魅力。
npm install -g [email protected]
There should be a clear documentation describing breaking changes and compatibility issues between the two.
应该有一个清晰的文档来描述两者之间的重大更改和兼容性问题。
回答by mohammad javad ahmadi
I think delete this directory and clean the cache of npmis better:
我认为删除这个目录并清理缓存npm更好:
rm -rf ~/.node-gyp/
rm -r node_modules/.bin/;
rm -r build/
npm cache clean
and you can test
你可以测试
npm install -g node-gyp
and
和
npm install -g node-pre-gyp
finally:
最后:
npm install <your module>
回答by HAOBO LUO
I got the same problem when installed the gazebo gzweb. I found out that apt install nodejsinstall the "node" in the direction of "/usr/bin/". You can verify by which node. But node -vis still referring to "/usr/local/bin/node" which is a wrong version I failed to uninstall.
Thus as my solution:
安装gazebo gzweb时我遇到了同样的问题。我发现apt install nodejs在“/usr/bin/”的方向安装“node”。您可以通过 验证which node。但node -v仍然指的是“/usr/local/bin/node”,这是我无法卸载的错误版本。因此作为我的解决方案:
rm -rf /usr/local/bin/node
cp -i /usr/bin/node /usr/local/bin/
cp -i /usr/bin/nodejs /usr/local/bin/
Steps:
脚步:
sudo apt-get install npm
npm install -g n
n stable
npm install [email protected] -g
ln -s /usr/local/bin/npm /usr/bin/npm
sudo apt-get install npm
npm install -g n
n stable
npm install [email protected] -g
ln -s /usr/local/bin/npm /usr/bin/npm
回答by Taylan
CentOS 6 users
CentOS 6 用户
Node 10+ requires GCC4.9. And apparently CentOS 6 doesn't have it. You can use these commands before npm install as a workaround (tested with Node 11 NPM 6).
节点 10+ 需要 GCC4.9。显然 CentOS 6 没有它。您可以在 npm install 之前使用这些命令作为解决方法(使用 Node 11 NPM 6 测试)。
yum install devtoolset-7
source scl_source enable devtoolset-7
回答by kheengz
Follow these steps to resolve the issue.
请按照以下步骤解决问题。
- Make sure you have build-tools installed.
- Update node-gyp
- Delete package-lock.json and node modules folder and run npm install again.
- Deleting ~/.node-gyp folder and run npm install again.
- 确保安装了构建工具。
- 更新节点-gyp
- 删除 package-lock.json 和 node modules 文件夹并再次运行 npm install 。
- 删除 ~/.node-gyp 文件夹并再次运行 npm install。
Source: https://codeforgeek.com/make-failed-with-exit-code-2/

