NPM common setup Issues and Fix

Published by Jayaraj on

In this article I am going to walk-through over the common issues faced during NPM Install, restore packages, root cause of the problem and Solution to fix.

What is NPM?

npm (Node Package Manager) is an online repository for the publishing of open-source Node.js projects. It is a command-line utility for interacting with said repository that aids in package installation, version management, and dependency management.

Scenario 1: Behind corporate web proxy

For those who, like me are behind a corporate web proxy setting up Node.js and using npm can be a real pain. I discover that npm uses a configuration file (.npmrc) and it can be added to via the command line npm config set or edit.

Issue: 

Any of the below issue might show up,

  1. Behind a corporate proxy.
  2. General authentication failure due to bad user ID or authentication token.
  3. Wrong proxy was configured and because of that npm was unable to download packages.

Solution:

Open an command prompt or terminal session and run the following command.

npm config edit

Text file (.npmrc) is opened for edit. Now change the relevant values for UserName, Password, Corporate Proxy and Proxy port number in below format, Save and close.

proxy=http://USERNAME:PASSWORD@PROXY:PORT/
strict-ssl=false
registry=http://registry.npmjs.org/

Note: If Password have values such as “@” or “/”, it should be converted to relevant encoded value such as using “%40” for “@” character.

Scenario 2: npm Install hangs/struck for long time

For those who are wondering npm shows no progress even after minutes running the npm install command.

Solution:

Run the npm install command with Verbose attribute to get more trace details as below,

npm install {package} --verbose

 

Categories: CoderCore

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.