Last updated: Apr 4, 2024
Reading timeยท4 min
The error "npm ERR! code 1 command failed" occurs when you aren't able to install a specific NPM package or a specific version of an NPM package with your version of Node.js.
To solve the error, install a version of the package that is compatible with your Node.js version and update your dependencies.
npm ERR! code 1 npm ERR! path /home/bobbyhadz/Desktop/react-projects/ecommerce/node_modules/node-sass npm ERR! command failed npm ERR! gyp verb cli [ npm ERR! gyp verb cli '/usr/local/bin/node', npm ERR! gyp verb cli '/home/bobbyhadz/Desktop/react-projects/ecommerce/node_modules/node-gyp/bin/node-gyp.js', npm ERR! gyp verb cli 'rebuild', npm ERR! gyp verb cli '--verbose', npm ERR! gyp verb cli '--libsass_ext=', npm ERR! gyp verb cli '--libsass_cflags=', npm ERR! gyp verb cli '--libsass_ldflags=', npm ERR! gyp verb cli '--libsass_library=' npm ERR! gyp verb cli ] npm ERR! gyp info it worked if it ends with ok npm ERR! Build failed with error code: 1
You can check which package caused the error on the second line of your error message.
# ๐๏ธ node-sass npm ERR! path /home/bobbyhadz/node_modules/node-sass
The first thing you should try is to install the latest version of the package.
npm install node-sass@latest --legacy-peer-deps
Make sure to replace node-sass
with the name of the package that caused the
error in your case.
node-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 # ๐๏ธ 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.