Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to publish to npm registry, 401 error

Tags:

npm

I am unable to publish my package to npm. I am logged in as a user with correct access to that package.

After logging in, I run this command to show I am logged in:

$ npm whoami
ganchrowsci

Then I run this command to ensure that the current user has access to the current package:

$ npm access ls-collaborators
{
  "ganchrowsci": "read-write"
}

And then I run publish and it ends with an error:

$ npm publish
...<snip>
npm ERR! code E401
npm ERR! 401 Unauthorized - PUT http://registry.npmjs.com/gs-utils - You must be logged in to publish packages.

This is clearly showing that I am not logged in, but that is also clearly not true. I can't understand why I'm not able to publish. Can you explain what I am doing wrong?

Another piece of information is that, this used to work and we have published many versions of this package, but we haven't published recently. It's only this latest change that we're having trouble with.

like image 289
Andrew Eisenberg Avatar asked Jun 14 '19 22:06

Andrew Eisenberg


People also ask

How to fix E401 error in NPM V7?

If you get E401 with a private npm registry after upgrading to npm v7, remove your package-lock.json and reinstall. The registry url setting in .npmrc needs to match the http/https protocol in your package-lock.json exactly. Use command better-vsts-npm-auth and it should work.

What is the%2F error in NPM install?

For scoped packages (@angular/router), npm install uses an encoded slash for the “/” between the scope and the package name. This will be displayed as %2f in your Artifactory request logs: There are two (2) locations where the encoded slash may fail.

How do I publish npm packages to Artifactory?

To publish npm packages to Artifactory, you'll need to configure your package.json to point to your Artifactory npm repository: After doing so, you can run npm publish to deploy a .tar.gz file to the local repository: A common setting for npm is the Enable Dependency Rewrite option for virtual repositories.

How does the npm client request metadata on the package?

The NPM client requests metadata on the package: 2. The metadata contains the download link for the tar.gz file: The metadata is pulled from a “ package.json ” file found in each NPM .tgz file: […] For scoped packages (@angular/router), npm install uses an encoded slash for the “/” between the scope and the package name.


Video Answer


1 Answers

I created an account in npm (https://www.npmjs.com/). Then created a token in that account.

The following command worked for me:

npm adduser --registry=https://registry.npmjs.org/:_authToken=<token-from-npm>

like image 89
Sherry Mathews Avatar answered Oct 17 '22 16:10

Sherry Mathews