How to fix npm install command not working (2024)

How to fix npm install command not working (1)

The npm install command is used for installing JavaScript packages on your local computer.

When developing web projects, you may see issues that cause the npm install command to fail.

You need to see the error message generated in the terminal for clues to resolve the error.

Some of the most common issues for npm install not working are as follows:

  • npm command not found
  • No package.json file describing the dependencies
  • Integrity check failed error
  • For Windows: Python not found

Let’s see how you can resolve these errors next.

The npm command not found error

To run the npm install command, you need to have npm installed on your computer

$ npm installsh: command not found: npm

The error above happens when npm can’t be found under the PATH environment variable.

First, you need to make sure that npm is installed on your computer.

npm is bundled with Node.js server, which you can download from the nodejs.org website.

Once you downloaded and installed Node.js, open the terminal and run the npm -v command.

You should see the version of npm installed on your computer as follows:

Once you see the npm version, you should be able to run the npm install command again.

For more details, visit the fixing npm command not found error article I’ve written previously.

ENOENT: No package.json file

The npm install command looks for a package.json file in order to find the packages it needs to install.

You need to make sure you have a package.json file right in the current directory where you run the command.

You can run the ls -1 command as follows:

$ ls -1index.jspackage-lock.jsonpackage.json

Once you see there’s a package.json file in the output as shown above, then you can run the npm install command.

For this reason, you should always run the npm install command from the root directory of your project.

By the way, npm install will install packages already listed under the dependencies object of your package.json file.

Suppose you have a package.json file as shown below:

{ "name": "n-app", "version": "1.0.0", "description": "A Node application", "dependencies": { "jest": "^28.1.1", "typescript": "^4.5.5", "webpack": "^2.7.0" }}

Then npm install will install jest, typescript, and webpack to the generated node_modules/ folder.

If you need to install a new package, then you need to specify the name like these examples:

# 👇 install react packagenpm install react# 👇 install react, react-dom, and axios packagesnpm install react react-dom axios

You can install one or many packages with the npm install command.

Integrity check failed error

When you have a package-lock.json file in your project, then npm will check the integrity of the package you downloaded with the one specified in the lock file.

When the checksum of the package is different, then npm will stop the installation and throw the integrity check failed error.

The following is an example of the error:

npm ERR! code EINTEGRITYnpm ERR! Verification failed while extracting @my-package@^1.2.0:npm ERR! Verification failed while extracting @my-package@^1.2.0:npm ERR! Integrity check failed:npm ERR! Wanted: sha512-lQ...HA== npm ERR! Found: sha512-Mj...vg==

When this happens, you can fix the issue by verifying the cache:

npm cache verify

When the command is finished, run npm install again.

If you still see the error, then delete your lock file and clean the npm cache.

Run the following commands from your project’s root directory:

# 👇 remove the lock filerm package-lock.json# 👇 remove the node_modules folderrm -rf node_modules# 👇 Clear the npm cachenpm cache clean --force# 👇 run npm install againnpm install

That should fix the issue with the integrity check.

For Windows only: Python not found

When running npm install on Windows, you may see an error that says Can’t find Python executable as shown below:

> node-gyp rebuild/n-app>node "\..\node_modules\node-gyp\bin\node-gyp.js" rebuildnpm http 304 https://registry.npmjs.org/bcryptgyp ERR! configure errorgyp ERR! stack Error: Can't find Python executable "python",you can set the PYTHON env variable.

The node-gyp module is a Node.js tool for compiling native modules written in C and C++. It requires Python to run properly.

Instead of installing Python by yourself, you can install the Windows Build Tools which has Python included.

This is because Windows also requires Visual Studio build tools to make node-gyp run successfully.

If you install only Python, then you may find that you need the build tools later.

Please note that the latest version of Node.js for Windows installer already includes the build tools by default.

But if you can’t update your Node.js version yet, then installing the build tools manually should help you fix this error.

Conclusion

The npm install command may fail to work because of many reasons.

When the command doesn’t work, you need to check the output first and see what specific error you have.

Try a Google search to fix the issue. When you don’t see a solution, try posting a new question at Stack Overflow mentioning the things you have tried to fix the issue.

Good luck resolving the issue! 👍

How to fix npm install command not working (2024)

FAQs

How to fix npm install command not working? ›

Common npm install errors and their solutions. This error occurs when npm does not have the necessary permissions to install packages or modify certain files or directories. To resolve this issue, you can try running the command with administrative privileges or fix the permissions for the specific directory.

Why is the npm install command not working? ›

Common npm install errors and their solutions. This error occurs when npm does not have the necessary permissions to install packages or modify certain files or directories. To resolve this issue, you can try running the command with administrative privileges or fix the permissions for the specific directory.

How to make npm install work? ›

To install a package, npm uses the following algorithm:
  1. load the existing node_modules tree from disk.
  2. clone the tree.
  3. fetch the package.json and assorted metadata and add it to the clone.
  4. walk the clone and add any missing dependencies.
  5. dependencies will be added as close to the top as is possible.
Sep 22, 2020

How do I force npm to install? ›

To force an NPM package to install, you can use the --force flag. This will tell npm to ignore any errors or conflicts that it encounters during installation. You should use the --force flag with caution, as it can lead to unexpected results.

Why my npm start command is not working? ›

Make sure that all items have read/write permission, otherwise attempting to run “npm start” will throw an error. It is also possible that you may be in the wrong directory when running “npm start”. Make sure that you are in the root folder of your project when you run this command.

How to do npm install again? ›

Reinstall a single npm package
  1. Uninstall the package: npm uninstall <package-name>
  2. Install the package: npm install <package-name>
May 20, 2024

How do I fix a broken npm? ›

Broken npm installation

If your npm is broken: On Mac or Linux, reinstall npm. Windows: If you're on Windows and you have a broken installation, the easiest thing to do is to reinstall node from the official installer (see this note about installing the latest stable version).

What is the command to install npm? ›

If NPM is not installed or is outdated, you can install it separately or update it by running the command npm install -g npm in the terminal. This will update NPM to the latest version. To verify the NPM installation, type npm -v in the terminal. It should display the latest version of NPM.

How to install npm completely? ›

How to Install Node.js and NPM on Windows?
  1. Step 1: Download the Installer. Download the Windows Installer from NodeJs official website. ...
  2. Step 2: Install Node.js and NPM. After choosing the path, double-click to install .msi binary files to initiate the installation process. ...
  3. Step 3: Check Node.js and NPM Version.
Feb 14, 2024

How do I start npm installation? ›

The Basics: Getting started with npm
  1. Using npm init to initialize a project.
  2. Using npm init --yes to instantly initialize a project.
  3. Install modules with npm install.
  4. Install modules and save them to your package.json as a dependency.
  5. Install modules and save them to your package.json as a developer dependency.
Feb 10, 2022

How to install npm on glitch? ›

Now, here's how to add an NPM package to your Glitch project:
  1. Open the project in the editor.
  2. In the file view on the left, click on package. ...
  3. Click the + ADD PACKAGE button which can be found at the top of the package. ...
  4. Use the search box to find the NPM package that you would like to add to your project.
May 31, 2023

How to check npm installed or not in cmd? ›

To see if NPM is installed, type npm -v in Terminal. This should print the version number so you'll see something like this 1.4. 28. Create a test file and run it.

How to enable npm command? ›

npm Install Globally

Install a package on your system globally. Use the following command to install a package on your system globally: npm install <package_name> --global.

How to check if npm is installed or not? ›

To see if NPM is installed, type npm -v in Terminal. This should print the version number so you'll see something like this 1.4.

Top Articles
Bamboo
The new Big 4 partners' average age between 33 and 35. Will becoming a
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 6422

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.