Monday, October 10, 2022

[SOLVED] npm install fails due private packages not found although the token is set in the .npmrc file

Issue

Environment details are like below:

  • Ubuntu 20.04
  • Node v10.22.1
  • npm 6.14.6

I have a frontend project(react) where I need to create CI/CD pipeline. I failing to set it up locally due to private packages not being found during npm install.

The error is like below:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@org/package-name/-/package-name-0.1.24.tgz
npm ERR! 404 
npm ERR! 404  '@org/package-name@^0.1.24' 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 It was specified as a dependency of 'project-name'
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!     /home/rando/.npm/_logs/2021-09-23T07_52_46_228Z-debug.log

First, I have verified if I have access to this package by authenticating with my account in npmjs.com. Below you can see that I am part of the organization and have access to all packages of that organization.

enter image description here

I have configured the .npmrc file located in /home/user like below:

registry=https://registry.npmjs.com/
//registry.npmjs.com/:_authToken=${authToken}

I have generated multiple authentication tokens from my npmjs.com account and tried running npm install after placing the newly generated token on the .npmrc file.

Also, I tried to install the library in isolation like below:

npm i @org/package-name

But still failed with the same error 404.

I tried to log in the terminal like below:

npm login
Username:
Password:
Email: (this IS public) {may email}
Logged in as {my username} on https://registry.npmjs.com/.

npm i @org/package-name

And it still failed with the same error. I will appreciate any help toward solving this issue.

Regards, Rando.


Solution

I was able to fix this issue by modifying the .npmrc file like below:

//registry.npmjs.com/:_authToken=${authToken}

Removing the registry=https://registry.npmjs.com/ fixed the issue. I don't quite understand why specifying the registry cause this trouble.



Answered By - Rando Shtishi
Answer Checked By - Gilberto Lyons (WPSolving Admin)