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

22

137

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?

Hamitic answered 1/6, 2017 at 19:54 Comment(6)
Whenever you encounter such errors, the actual error(s) will appear before these lines you've currently posted in the console.Chanty
@Chanty I added the lines of code I am getting before the errorHamitic
Does switching to node v6 help?Miracle
@Miracle What would be the command to do so? It seems to me that the bufferutil comes up a lot, would anyone know what that is?Hamitic
What is your compiler and compiler version?Chanty
For Mac OS Catalina, downgrading to Node 10.x solved my problem.Argentous
H
23

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.

Hamitic answered 2/6, 2017 at 15:38 Comment(1)
you may try yarn-check package it is very helpfulThreeply
C
163

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

Chanson answered 9/4, 2019 at 10:7 Comment(8)
I hate it when this is the solutionDykstra
This worked for. In my case it was yarn.lock file which I had to delete.Arther
yes.. if you use yarn to build instead of npm. I'll update my answer.. thank youChanson
npm upgrade should update all packages to latest. See docs.npmjs.com/cli/v7/commands/npm-update or npmjs.com/package/npm-upgradeWheeze
@PaulRazvanBerg I hate it much more when this ISN'T the solution.Outlaw
Holy crap, can't believe it was as simple as that!!Trod
What this is most likely doing is the same thing as a npm upgrade, I think. You could try upgrading bcrypt, if you depend on it directly.Gumdrop
Do me a big feverAustinaustina
E
51

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

macOS:

xcode-select --install

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.

Epidote answered 13/1, 2020 at 15:36 Comment(6)
How to do this for mac?Wheeze
For now I'm trying this..not a huge fan of homebrew or ruby, but if it works.... docs.macstadium.com/docs/install-osx-build-toolsWheeze
Xcode is installed. I am running on MacOS 11.4 - I'm wondering if I'll be forced to update the system before I can move forward with this issue. Unfortunately my internet is garbage and it's an 8GB download - which always fails a GB or 2 into the download, and then wants to start over again from the beginning. Any idea if this is critical to making it work?Wheeze
@Wheeze I don't expect you need to update macOS. Did you also install the Command Line Tools for Xcode?Epidote
That's it. After two days I stumbled here. Solved for Ubuntu 22.04.1 (same solutions in 3 different machines)Magnetometer
fixed my problem on ubuntu 22.04Wooer
K
27

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 [email protected]

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

Karrikarrie answered 7/5, 2019 at 7:38 Comment(4)
This is the answer I've been looking for for 3 days!! Although I was experiencing the problem inside a Docker container (rather than on a host machine), it does sound like I've been down the same route as you - trying to re-install node, clearing caches etc. For me, basing the container on node:current-alpine was the mistake (version 16 at time of writing). Changing to node:12.2.0-alpine fixed my problem and allowed npm install complete. I suspect that the underlying reason for my resolution is the same as yours -- the older Docker container essentially downgrades the version of node.Photogene
How can one check if a specific version of node-gyp is a compatible with a specific version of node?Dykstra
This works for me. Additional resources to the answer: (1) #47008659 (2) nodejs.org/en/download/releasesBigot
For me I down graded to version 14 from version 16 of node and the issue went away.Paralytic
H
23

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.

Hamitic answered 2/6, 2017 at 15:38 Comment(1)
you may try yarn-check package it is very helpfulThreeply
C
15

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.

Contamination answered 7/9, 2018 at 18:46 Comment(2)
This solved it for me. Downgraded from Node 10 to Node 8 and got my repo running locally.Performative
I don't have anything like "engines": { "node": "7.10.2"locally (8.11.3) }, in my package.json. Can't figure out what version of Node it think it isWheeze
S
15

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 error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?.

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.

Sleekit answered 25/1, 2022 at 6:25 Comment(0)
I
9

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

Innuendo answered 24/7, 2018 at 18:12 Comment(1)
Warning: removing ~/.npmrc will delete your other configurations, for example your default author name.Dykstra
B
4

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>
Bartko answered 15/9, 2019 at 8:8 Comment(0)
T
4

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.

Tanaka answered 22/5, 2022 at 7:40 Comment(0)
T
3

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.

Tracitracie answered 29/4, 2021 at 17:18 Comment(0)
P
2

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
Pinnatisect answered 5/4, 2019 at 20:30 Comment(0)
B
2

change Node version from 16.15.1 to 14.17.3

 sudo n 14.17.3
Bilberry answered 17/8, 2022 at 9:38 Comment(1)
This worked for me. npm install failed in my project. I saw a recommendation to upgrade it and did it. I had npm 16.15.1. npm install failed again. Cleaning caches did not help. Downgrading npm and cleaning caches helped. Command I used npm install -g [email protected] --forceTopotype
I
1

I had the same problem, but didn't realise it was being caused by an error further up in the logs. python was not installed correctly.

env: python: No such file or directory
make: *** [Release/sass.a] Error 127
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/private/var/folders/5q/3y3xtdk11g11sgclgtc6vtvh0000gn/T/xfs-b4670056/node_modules/node-gyp/lib/build.js:194:23)
Intracutaneous answered 13/2, 2023 at 15:19 Comment(0)
U
0

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

Unsociable answered 30/5, 2019 at 14:0 Comment(0)
B
0

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

Belly answered 27/1, 2020 at 23:9 Comment(0)
Y
0

Follow these steps to resolve the issue.

Debug #1: Deleting package-lock.json file

rm -rf package-lock.json
rm -rf node_modules

npm install

Debug #2: Deleting .node-gyp folder

rm -rf ~/.node-gyp

npm install

Debug #3: Re-install node-gyp

npm i -g node-gyp

Debug #4: Install build essentials

sudo apt-get install -y build-essential

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

Yseult answered 24/4, 2020 at 10:2 Comment(1)
please update your answer with corresponding commandsSillimanite
S
0

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
Satin answered 13/4, 2021 at 5:13 Comment(3)
Please don't post the same answer to multiple questions. They will get flagged for deletion and, if multiple questions have the same answer you should consider flagging those questions as duplicates rather than repeating your answer.Villiform
@DavidBuck Thanks for pointing this out. I was not aware of it. The motive is to provide correct solution.Satin
Understood. This answer has some helpful advice.Villiform
S
0

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

🙃 🥴

Supat answered 8/1, 2022 at 8:54 Comment(0)
C
0

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

Chaechaeronea answered 11/5, 2022 at 2:18 Comment(0)
P
0

Sometimes the project depends on older node version. Ask the owner about appropriate version or make a try with 'nvm install

Proleg answered 14/9, 2022 at 15:21 Comment(0)
K
0

what worked for me and seems as the right solution i did not found here is replacing node-sass which is deprecated to the sass library i used this guide: https://dev.to/ccreusat/migrating-from-node-sass-to-sass-dart-sass-with-npm-3g3c basically change the library:

"devDependencies": {
    "node-sass": "version_installed"
}

to

"devDependencies": {
    "sass": "^1.49.9"
}

and change the sass commands somewhat like so (package.json):

"scripts": {
 "build-sass": "node-sass --output-style compressed <css dist> <scss source files>"
}

to:

"scripts": {
 "build-sass": "sass --style=compressed <css dist> <scss source files>"
}
Kymry answered 16/1 at 14:36 Comment(3)
It would be ideal to quote the relevant part of the links here in case it's inaccessible in the future. In short, explain how to make the switch of libraries.Mathia
@Mathia is that looks better?Kymry
I'm not familiar with this topic,but it looks like it. Thanks. I'll let specialists vote on this.Mathia
T
0

I solved it on linux using

npm install --python=/usr/bin/python2.7

Change the python path if you are on Windows or macOS

Terence answered 19/4 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.