Surviving the npm ERR! 404 with private packages

How to fix a common issue when installing private packages with npm

Marco Rapaccini
4 min readFeb 19, 2021
nasty problem maker

Almost every developer knows npm, the JavaScript package manager very useful for faster development and for downloading the entire Internet (yes, npm has this fault… I recommend to read this great article to understand better npm’s problems).

npm is useful and at the same time useless

Context: I’m doing some pair programming with one of my colleagues and we are trying to install a private npm package.

Private packages are npm packages that are not accessible to everyone, but only to members of a specific organization that have access rights.

On my Linux Ubuntu 20.4 instance with WSL (Windows Subsystem for Linux) for Ubuntu 20.4, I can run without any problem the installation command after npm login:

npm login
sudo npm i -g -D @organizationName/cli

But my colleague is getting the following error on his Linux Debian 10 machine:

sudo npm i -g -D @organizationName/cli
npm ERR! code E404
npm ERR! 404 Not Found - GET - Not found
npm ERR! 404
npm ERR! 404 '@organizationName/cli@*' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a npm
ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-02-19T18_05_38_311Z-debug.log

He is correctly logged with npm login, but he can’t install the private package.

“What could be the problem?”

Photo by bruce mars on Unsplash

“Maybe it’s the npm version”.

So, we update it on his Debian machine:

npm install npm@latest -g

Yes, he had an older version of npm.

But, when trying to run the command again…

sudo npm i -g -D @organizationName/cli
npm ERR! code E404

If the issue is not the version and is not the login, what could it be?

At this time, we start our holy grail research on Stack Overflow.

This solution says that we have to configure the npm registry:

npm config set registry

“Let’s try with the registry”

Guess what, same error.

Photo by Francisco Gonzalez on Unsplash

Then, a wrong intuition: “it’s clear, we are trying to download from npm, maybe we have to download from the private package link”.

Blinded from this suggestion, we try miserably a custom link for the registry:

npm config set registry

Nope, idiot!

I say to myself after doing the shameful copy-paste-without-thinking.

Now, the registry is a mess, let’s go back to the default version (yes, again):

npm config set registry

It’s time to think out of the box!

Why did I decide to become a developer? I hate it…

The great question that every programmer has when something is recursively wrong.

Ok, let’s focus again: we do other Google searches without any luck.

Good, it’s time to cry.

Photo by Tom Pumford on Unsplash

Then, my eyes go to the 4387643th opened tab in the browser, the same of the first StackOverflow link, second voted answer.

Alexus, our random saviour, writes: “in my case it was .npmrc file in my project dir, which kept overwriting my global registry url. As soon as I deleted it, I could finally use npm install”.

Maybe we still have some hope

After hours of desperation, my colleague finds the .npmrc file

ls -als

and then he deletes it in his /home/colleagueName/ directory:

rm /home/colleagueName/.npmrc

Then, he runs the installation command for the last time.

Photo by bruce mars on Unsplash

Yes, finally!

What we learned through this painful journey:

  • npm is tricky
  • never mess with the npm registry if not required
  • StackOverflow is our best friend, but we have to read every single reply
Photo by Javier Allegue Barros on Unsplash

To avoid our errors, I suggest you to follow this checklist when you are facing a npm ERR! 404 and you can’t fix it:

  • install latest npm version
  • login (if you are downloading a private package)
  • try to install the package
  • try to delete the .npmrc file from your home directory
  • re-try to install the package

If you want to learn more about .npmrc, I recommend these readings:

This is my first article here on Medium, hope you enjoyed it!

Thank you for reading.



Marco Rapaccini

Senior Software Engineer ~ Startup Technical Cofounder ~ R&D lover