Introduction
Welcome to this Byte! We’ll take a better have a look at the notorious npm ERR! gyp ERR! stack Error: 'make' failed with exit code: 2
. This error message would possibly look like a jumble of phrases and symbols, nevertheless it’s really a cry for assist out of your npm set up. We’ll dissect this error, perceive its root trigger, after which stroll you thru find out how to repair it.
Why will we get this error?
Quite a bit can go mistaken throughout an set up with npm, primarily as a result of there are loads of packages which might be constructed throughout set up utilizing instruments like node-gyp
. One widespread error you would possibly run into is make failed with exit code: 2
This error is normally thrown when npm is attempting to construct a package deal that features native C++ code. npm makes use of a software referred to as node-gyp
to compile and construct these native modules. If node-gyp
encounters an issue through the construct course of, it throws an error – on this case, the Error: `make` failed with exit code: 2
.
$ npm set up
# ...construct output
gyp ERR! construct error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/native/lib/node_modules/npm/node_modules/node-gyp/lib/construct.js:285:23)
gyp ERR! stack at emitTwo (occasions.js:125:13)
gyp ERR! stack at ChildProcess.emit (occasions.js:213:7)
gyp ERR! stack at Course of.ChildProcess._handle.onexit (inner/child_process.js:197:12)
gyp ERR! System Linux 4.5.12-ti-r64
gyp ERR! command "/usr/native/bin/node" "/usr/native/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /residence/initiatives/sa-web-cms/node_modules/bufferutil
gyp ERR! node -v v14.20.1
gyp ERR! node-gyp -v v3.7.4
gyp ERR! not okay
However particularly, what precisely does it imply that make
failed with exit code 2?
When make
fails with exit code: 2, it is normally as a result of there was an issue with the construct course of. This may very well be as a result of a wide range of causes, like lacking dependencies, syntax errors within the code, and even points with the construct surroundings.
Observe: Exit codes are a method for applications to speak what occurred throughout their execution. An exit code of 0 normally signifies that this system accomplished efficiently, whereas every other quantity signifies some kind of error.
Find out how to Repair the Error
Fixing the gyp ERR! stack Error: `make` failed with exit code: 2
is usually a bit difficult, because the precise downside could be hidden deep throughout the construct course of. Nevertheless, listed below are a number of steps which you can take:
- Reinstall the problematic package deal: One of many easiest issues you are able to do is simply to uninstall and reinstall the package deal inflicting the difficulty:
$ npm uninstall problematic-package
$ npm set up problematic-package
- Delete lock recordsdata: One other easy factor to attempt that, surprisingly, fixes loads of errors is to delete your lock file and reinstall, which could be executed with npm or yarn:
$ rm package-lock.json
# OR
$ rm yarn.lock
# THEN
$ npm set up
By “cleansing” your surroundings and forcing a full set up, you’ll be able to typically assist clear hard-to-find errors like this.
- Test your construct surroundings: Just be sure you have all the required construct instruments put in. This contains
make
, a C++ compiler, and Python.
$ make --version
GNU Make 4.2.1
$ gcc --version
gcc (GCC) 10.2.0
$ python --version
Python 2.7.18
- Replace your npm and node-gyp: Generally, the error could be as a result of a bug in npm or node-gyp. Updating these instruments to their newest model can usually repair the issue.
$ npm set up -g npm
$ npm set up -g node-gyp
Conclusion
On this Byte we tried to clarify what the error Error: `make` failed with exit code: 2
really is, why it happens, and some methods to repair it. It is one in every of many potential errors that may appear laborious to repair at first, however normally have a easy answer, like deleting a lock file and reinstalling.