Introduction
Welcome to this Byte! We will take a more in-depth take a look at the notorious npm ERR! gyp ERR! stack Error: 'make' failed with exit code: 2
. This error message may look like a jumble of phrases and symbols, but it surely’s truly a cry for assist out of your npm set up. We’ll dissect this error, perceive its root trigger, after which stroll you thru how one can repair it.
Why will we get this error?
Lots can go unsuitable throughout an set up with npm, primarily as a result of there are numerous packages which are constructed throughout set up utilizing instruments like node-gyp
. One frequent error you may run into is make failed with exit code: 2
This error is often thrown when npm is making an attempt to construct a bundle that features native C++ code. npm makes use of a software known as node-gyp
to compile and construct these native modules. If node-gyp
encounters an issue in the course of 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 /dwelling/tasks/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 often as a result of there was an issue with the construct course of. This may very well be as a consequence of quite a lot of causes, like lacking dependencies, syntax errors within the code, and even points with the construct atmosphere.
Word: Exit codes are a manner for applications to speak what occurred throughout their execution. An exit code of 0 often signifies that this system accomplished efficiently, whereas another quantity signifies some type of error.
The right way to Repair the Error
Fixing the gyp ERR! stack Error: `make` failed with exit code: 2
could be a bit difficult, because the precise drawback is likely to be hidden deep inside the construct course of. Nevertheless, listed here are just a few steps which you could take:
- Reinstall the problematic bundle: One of many easiest issues you are able to do is simply to uninstall and reinstall the bundle inflicting the difficulty:
$ npm uninstall problematic-package
$ npm set up problematic-package
- Delete lock information: One other easy factor to strive that, surprisingly, fixes numerous errors is to delete your lock file and reinstall, which may be completed with npm or yarn:
$ rm package-lock.json
# OR
$ rm yarn.lock
# THEN
$ npm set up
By “cleansing” your atmosphere and forcing a full set up, you may typically assist clear hard-to-find errors like this.
- Test your construct atmosphere: Just be sure you have all the mandatory 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 is likely to be as a consequence of a bug in npm or node-gyp. Updating these instruments to their newest model can typically repair the issue.
$ npm set up -g npm
$ npm set up -g node-gyp
Conclusion
On this Byte we tried to elucidate what the error Error: `make` failed with exit code: 2
truly is, why it happens, and some methods to repair it. It is one in all many potential errors that may appear arduous to repair at first, however often have a easy resolution, like deleting a lock file and reinstalling.