How to solve npm ERR! code 1 when running npm install (2024)

by Nathan Sebhastian

Posted on Jun 24, 2022

Reading time: 3 minutes

How to solve npm ERR! code 1 when running npm install (1)

The npm ERR! code 1 error usually occurs when you run the npm install command.

This cause of this error is that one of the dependencies you define in your package.json file fails to be installed properly on your computer.

The error message log looks as follows:

$ npm installnpm ERR! code 1npm ERR! path /n-app/node_modules/node-sassnpm ERR! command failednpm ERR! command sh -c node scripts/build.js...npm ERR! Build failed with error code: 1npm ERR! A complete log of this run can be found in:npm ERR! .npm/_logs/2022-06-24T03_37_26_246Z-debug-0.log

In the example above, you can see that there is an npm ERR! path... defined right below the code 1 log:

$ npm installnpm ERR! code 1npm ERR! path /n-app/node_modules/node-sass

This means that npm fails to install the node-sass module that’s added as a dependency to the n-app project.

To resolve this error, you need to upgrade the dependency module that causes the error.

Let’s learn how to fix this error next.

Fix npm error code 1 by updating your dependencies

Here’s the package.json file of the n-app project:

{ "name": "n-app", "version": "1.0.0", "dependencies": { "axios": "^0.10.2", "node-sass": "^4.14.1", "webpack": "^4.0.0" }}

As you can see, there’s a dependency to the node-sass module version 4.14.1 in my project.

When looking into the node-sass documentation, I found that there’s a table showing the Node versions supported by the package:

How to solve npm ERR! code 1 when running npm install (2)

Since I have Node v16.15.1 on my computer, this means I must use node-sass v6.0+ to resolve the issue.

Update the node-sass dependency to the latest version:

{ "dependencies": { "axios": "^0.10.2", "node-sass": "^7.0.1", "webpack": "^4.0.0" }}

Then run npm install again. This time, the dependencies are installed without any error:

$ npm installadded 307 packages, and audited 308 packages in 50sfound 0 vulnerabilities

It’s always recommended to update all your dependency packages to the latest version to avoid compatibility issues with Node.

You can use npm-check-updates to help you with updating the dependencies:

# 👇 check your package.json for dependency updatesnpx npm-check-updates# 👇 write newer version in package.jsonnpx npm-check-updates -u# 👇 install the latest versionnpm install

If you don’t want to update all dependencies at once, you can update them one by one using the npx npm-check-updates output as a reference.

For example, here’s the output for n-app project:

$ npx npm-check-updatesChecking /n-app/package.json[====================] 3/3 100% axios ^0.21.2 → ^0.27.2  node-sass ^4.0.1 → ^7.0.1  webpack ^4.73.0 → ^5.73.0 Run npx npm-check-updates -u to upgrade package.json

Using the output above:

  • Update one package version in package.json file
  • Then run npm install
  • Make sure your application runs perfectly and pass all tests

Repeat the steps above until you have all package versions updated.

Fix npm error code 1 by downgrading Node (not recommended)

The other way to fix the issue is to downgrade your Node.js version.

In the example above, there are specific Node.js versions supported by specific node-sass versions. You need to make sure that you are using the Node version supported by your module.

This fix is not ideal because you may have other module with compatibility issues once you downgrade Node.

The best way to solve the issue is by updating Node.js and all your dependencies to the latest stable version as explained above.

And that’s how you fix the npm error code 1 issue in your project.

How to solve npm ERR! code 1 when running npm install (2024)
Top Articles
Latest Posts
Article information

Author: Chrissy Homenick

Last Updated:

Views: 5806

Rating: 4.3 / 5 (74 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Chrissy Homenick

Birthday: 2001-10-22

Address: 611 Kuhn Oval, Feltonbury, NY 02783-3818

Phone: +96619177651654

Job: Mining Representative

Hobby: amateur radio, Sculling, Knife making, Gardening, Watching movies, Gunsmithing, Video gaming

Introduction: My name is Chrissy Homenick, I am a tender, funny, determined, tender, glorious, fancy, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.