Last updated: Apr 4, 2024
Reading timeยท5 min
make
failed with exit code: 2The error "npm ERR! gyp ERR! stack Error: make
failed with exit code: 2"
occurs when there's a glitch in your package-lock.json
file or you try to
install an outdated or incompatible version of an NPM package.
To solve the error, delete your node_modules
and package-lock.json
file
and rerun the npm install
command.
โ๏ธ remote: gyp ERR! build error remote: gyp ERR! stack Error: make failed with exit code: 2 remote: gyp ERR! stack at ChildProcess.onExit remote: gyp ERR! stack at ChildProcess.emit (node:events:390:28) remote: gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12) remote: gyp ERR! remote: gyp ERR! command "/tmp/build_47b2dcad/bin/node" "/tmp/build_47b2dcad/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" remote: gyp ERR! cwd /tmp/build_47b2dcad/node_modules/node-sass remote: gyp ERR! node -v v16.13.1 remote: gyp ERR! node-gyp -v v3.8.0 remote: gyp ERR! not ok remote: Build failed with error code: 1
The first thing you should try is to reinstall your node_modules
.
Open your terminal in your project's root directory (where your package.json
file is) and delete your node_modules
and package-lock.json
(not
package.json
) files, rerun npm install
and restart your dev server.
# ๐๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force npm install
Make sure to restart your IDE and dev server if the error persists.
If you are on Linux, make sure you have the meta-packages installed by running the command that's specific to your operating system.
# ๐๏ธ Debian (Ubuntu) sudo apt install -y build-essential # ๐๏ธ CentOS, RHEL sudo yum install gcc gcc-c++ make # ๐๏ธ Fedora sudo dnf groupinstall "Development Tools" "Development Libraries"
Try to rerun your npm install
command after installing the build tool packages
and restart your development server.
If you are on macOS or Linux, try to delete your ~/.node-gyp
folder and rerun
npm install
.
rm -rf ~/.node-gyp npm install
The error also commonly occurs when using the node-sass
package, if you don't
use node-sass
, scroll down to the next subheading.
sass
package instead of the deprecated node-sass
packagenode-sass
scroll down to the next subheading.If you got the error when installing the
node-sass package, install the
sass package instead because node-sass
has been deprecated.
Open your terminal in your project's root directory (where your package.json
file is) and run the following commands.
# ๐๏ธ with NPM npm uninstall node-sass npm install sass --save-dev # ๐๏ธ or with YARN yarn remove node-sass yarn add sass --dev
The two commands uninstall the deprecated node-sass
module and install the
sass
module.
Try to restart your development server after running the commands.
Alternatively, you can install a compatible version of node-sass
.
node-sass
module, you have to install a version of node-sass
that is compatible with your Node.js version.The table in this section of the
node-sass
npm page shows which node-sass
version you should install for your
version of Node.js.
You can use the node --version
command to get your version of Node.js.
node --version
Here is part of the table.
NodeJS version | Supported node-sass version |
---|---|
Node 19 | 8.0+ |
Node 18 | 8.0+ |
Node 17 | 7.0+, <8.0 |
Node 16 | 6.0+ |
Node 15 | 5.0+, <7.0 |
Node 14 | 4.14+ |
Node 13 | 4.13+, <5.0 |
For example, if your Node.js version is 17, you would install version 7 of
node-sass
.
# ๐๏ธ if your Node.js version is 17 npm install node-sass@7 --save-dev --legacy-peer-deps # ๐๏ธ for YARN with Node.js version 17 yarn add node-sass@7 --dev
Your node-sass
version has to be compatible with your Node.js version,
otherwise, the error occurs.
node-sass
version in the devDependencies section of your package.json
file.If you have a recent version of Node.js installed and your package.json
file
contains older versions of packages that are not compatible with your Node.js
version, the error occurs.
You can use the
npm-check-updates package to
update your package.json
dependencies to the latest version.
Open your terminal in your project's root directory (where your package.json
file is) and run the following command.
package.json
file to version control (e.g. git
) because the following 2 commands will update the versions of your packages in your package.json
file.npx npm-check-updates -u npm install
If the error persists, try to delete node_modules
and
package-lock.json and reinstall.
If the error is not resolved, try to delete your node_modules
and
package-lock.json
(not package.json
) files, rerun npm install
and restart
your IDE.
# ๐๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force npm install
npm
versionTry to update your NPM version by running the following command.
npm install -g npm@latest # ๐๏ธ If you get a permissions error on macOS / Linux sudo npm install -g npm@latest
If you get a permissions error on Windows, open CMD as an administrator and rerun the command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
npm install -g npm@latest npm install -g npm@latest --force
Try to run the npm install
command after updating your npm
version.
If the error persists, try to install the long-term supported version of Node.js.
You might be using a Node.js version that is not supported by the packages you're trying to install.
You can check your Node.js version with the node --version
command.
You can use the node --version
command to get your Node.js version.
node --version
If you use nvm
, you can update your version of Node.js and npm
with the
following 2 commands.
nvm install --lts nvm use --lts
You can also use the n package to manage your Node.js version.
npm cache clean -f npm install -g n n stable
If you get a permissions error when issuing the commands, open CMD as an
administrator (Windows) or prefix the commands with sudo
(macOS and Linux).
sudo npm cache clean -f sudo npm install -g n sudo n stable
Alternatively, you can download the long-term supported version of Node.js from the official nodejs.org website.