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

Solution 1:

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:

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:

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 4:

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.