简体   繁体   中英

NPM install resulting in 401 Unauthorized for private repo

I have the following line in my dependencies in package.json :

"log": "https://git.mydomain.com/myproject/myrepo/repository/archive.tar.gz?ref=0.1.0",

I get the following:

km@Karls-MBP ~/dev/vertica (km/ref) $ npm install
npm ERR! code E401
npm ERR! 404 401 Unauthorized: log@https://git.mydomain.com/myproject/myrepo/repository/archive.tar.gz?ref=0.5.0

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/km/.npm/_logs/2018-02-16T08_49_38_669Y-debug.log

I don't know if the issue is GitLab (where the repo exists) or NPM.

  • Node v8.9.4
  • NPM v5.6.0

Remove .npmrc from the Home Directory, it should be able to work. I did the same and it works for me.

My user directory .npmrc file had a stale authtoken as below.

//registry.npmjs.org/:_authToken=3615fa68-123a-4d72-b99a-772b5b1edc48

By removing this line, the npm installation works fine and no longer throws an authentication error.

You need to add user to npm registery

>> npm whoami [ it will return not authorized ]

To add new user follow below steps :-

>> npm adduser  (then enter your name and complex password and your email)

>> npm whoami   (return your registered name)

I got this when I used --prefer-offline

- npm ci --cache .npm --prefer-offline --unsafe-perm --no-optional

Removing that option fixed it.

In my case I have to change the content of .npmrc file to package-lock=false .

Now it works fine!

从根目录中删除 .npmrc 对我有用

I got the same error but the reason in my case was different than the above answers:

I discovered that the package-lock.json had some of the packages resolved to a private url instead of the typical public npm urls, so deleting the npm lock file and running npm install again solved it

But if this is the case, you need to check with the team still why this private url resolution happened instead of the normal one

removing the.npmrc from the root directory worked perfectly for me as well

I noticed this error for a public github repo. Removed the entry always-auth = true and was able to proceed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM