GYP ERR! build error. stack Error: 'make' failed with exit code 2

node.jsNpmIbm CloudCloud FoundryGyp

node.js Problem Overview


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.

This is the package.json file.

{
  "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_modules folder.

../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?

node.js Solutions


Solution 1 - node.js

> It worked after deleting package-lock.json and re run npm > install > > If you are using yarn to build your program delete yarn.lock and > re run yarn install

Solution 2 - node.js

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.

Solution 3 - node.js

This has been old yet consistent issue well documented at: 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_modules and even restart the system), what worked with me was downgrading the node.

I believe the versions mentioned in the log for node and node-gyp are incompatible. So I reverted to an older node version which worked like a charm.

npm install -g node@11.10.0

There should be a clear documentation describing breaking changes and compatibility issues between the two.

Solution 4 - node.js

In our case (since make failed), this issue could be resolved by installing the build / development tools:

Ubuntu / Debian:

apt-get install -y build-essential

CentOS:

yum install gcc gcc-c++ make 

Fedora 23 and above:

dnf install @development-tools

If this is not the solution, you might want to try to upgrade or downgrade node, remove package-lock.json and the node_modules folder, and then re-run npm install.

Solution 5 - node.js

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:

node --version
-> 8.11.3

Then look at your server setting in your 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.

Solution 6 - node.js

Delete the ~/.node-gyp folder and then the ~/.npmrc file.

Reboot your server and rerun npm install in your project folder

Edit:

Warning: removing ~/.npmrc will delete your other configurations

Solution 7 - node.js

In my case, it was cased by node-sass(version < 6.0.1) not supporting Node 16. Update node-sass to 6.0.1 and the issue is solved. see https://stackoverflow.com/questions/67241196/error-no-template-named-remove-cv-t-in-namespace-std-did-you-mean-remove/67303155#67303155.

One learning to my experience is that you should read the error messages very carefully and search the "root cause message". In my case it was error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?. It showed right above the GYP ERR! build error. stack Error: 'make' failed with exit code 2 line.

Solution 8 - node.js

I think delete this directory and clean the cache of npm is better:

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>

Solution 9 - node.js

I encountered this while building the image based on node:alipine.

Since my Dockerfile didn't specify the version, the latest one was used, which is Node 16 published 3 days ago at Docker Hub.

Downgrading it to 15 (node:15-alpine) solved the problem.

Solution 10 - node.js

If you are using NVM, you can also change to the version your package supports, like:

nvm install 7.10.2
nvm use 7.10.2

Solution 11 - node.js

I got the same problem when installed the gazebo gzweb. I found out that apt install nodejs install the "node" in the direction of "/usr/bin/". You can verify by which node. But node -v is still referring to "/usr/local/bin/node" which is a wrong version I failed to uninstall. Thus as my solution:

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

Solution 12 - node.js

CentOS 6 users

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).

yum install devtoolset-7
source scl_source enable devtoolset-7

Source: https://github.com/lovell/sharp/issues/1283

Solution 13 - node.js

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.

Source: https://codeforgeek.com/make-failed-with-exit-code-2/

Solution 14 - node.js

I am working on Ubuntu 20.04. I tried all the solutions mentioned here and nothing worked. The actual problem is versioning difference. I am sure the same package.json will be working fine on one of your team mate's local machine. You just need to ask your team mates about which npm and node version they are using and install it on your local machine.

To install specific version of npm:

sudo npm install -g npm@specific_npm_version_here

To install specific version of node:

sudo npm install -g n
sudo n specify_node_version_here

Solution 15 - node.js

If you're reading this after December 16th 2021, you may have been seeing build errors due to a Heroku node version upgrade issue.

As per the Heroku changelog:

> Ruby apps now default to Node version 16.13.1 and Yarn version 1.22.17 > Change effective on 16 December 2021 > > Applications using the heroku/ruby buildpack that do not have a > version of Node installed by another buildpack (such as the > heroku/nodejs buildpack) will now receive: > > Node version 16.13.1 (was previously 12.16.2) Yarn version 1.22.17 > (was previously 1.22.4)

https://devcenter.heroku.com/changelog-items/2306

 若

Solution 16 - node.js

i had the same error, and for me the solution was to downgrade the node version.

Solution 17 - node.js

In Linux it is fixed by installing build essential sudo apt-get install build-essential but in my Windows wsl2 installing only the build-essential did not solve the issue, I have to downgrade the node to 16.15.0 then it got resolved.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichael VaquierView Question on Stackoverflow
Solution 1 - node.jsNuOneView Answer on Stackoverflow
Solution 2 - node.jsMichael VaquierView Answer on Stackoverflow
Solution 3 - node.jsSlartibartfastView Answer on Stackoverflow
Solution 4 - node.jspiscatorView Answer on Stackoverflow
Solution 5 - node.jsIan EllisView Answer on Stackoverflow
Solution 6 - node.jsandromedaView Answer on Stackoverflow
Solution 7 - node.jsChris.ZouView Answer on Stackoverflow
Solution 8 - node.jsmohammad javad ahmadiView Answer on Stackoverflow
Solution 9 - node.jsИван БишевацView Answer on Stackoverflow
Solution 10 - node.jsRobinson MarquezView Answer on Stackoverflow
Solution 11 - node.jsHAOBO LUOView Answer on Stackoverflow
Solution 12 - node.jsTaylanView Answer on Stackoverflow
Solution 13 - node.jskheengzView Answer on Stackoverflow
Solution 14 - node.jsSaket SurajView Answer on Stackoverflow
Solution 15 - node.jsCalebView Answer on Stackoverflow
Solution 16 - node.jsalycecristinesView Answer on Stackoverflow
Solution 17 - node.jsRajarshi BiswasView Answer on Stackoverflow