Angular `ng update @angular/…` returns `401 Unauth

2019-06-19 00:19发布

问题:

npm -v returns 6.0.0

node -v returns v10.0.0

Angular CLI local and global version is 6.0.0

I create a new package with ng new sample, run npm install without issue, and then I try ng update @angular/core or ng update @angular/cli and get 401 Unauthorized in response.

Trying to run update on an already Angular 6 repository does seem redundant but I also have this issue with an Angular 5 repository.

I don't have a lot to go on from this error, is it something to do specifically with ng update or more likely to be some unrelated configuration outside of it?

回答1:

I was struggling with the same error message. For me it was caused by a custom .npmrc in the project directory which contained information about howto connect to our npm registry.

Here's how I resolved it:

  1. removed the file during the update (mv .npmrc backup.npmrc)
  2. removed all dependencies to artifacts from our internal npm registry from the package.json
  3. ran ng update @angular/cli
  4. moved file back to old position mv backup.npmrc .npmrc
  5. ran npm install (just to make sure)

I also created an angular-cli issue at https://github.com/angular/angular-cli/issues/10704



回答2:

By chance, were you running the app when you tried to update? I had the same issue and was able to update from 5.29 to 6.0.0 after stopping the app process and installing the latest cli globally.



回答3:

I had the same issue. Here is how i resolved it.

npm i -g @angular/cli@latest
ng update
ng update --all


回答4:

As indicated in the accepted answer this problem comes from having a custom registry defined somewhere in your configuration. Via .rc files such as .yarnrc or .npmrc or set directly with the npm config set registry <url> or yarn config set <name>:registry <url>. You don't need to undo these registry configurations to work around the issue! The ng update command will take a registry url as an argument. However, you will have to remove any reference to packages that rely on your custom registry. Don't worry the command will tell you what the offending packages are, just run the command like so:

for yarn:

ng update @angular/cli @angular/core --registry https://registry.yarnpkg.com

for npm:

ng update @angular/cli @angular/core --registry https://registry.npmjs.org

Should result in an error like: Not found : @fortawesome/fontawesome-pro

Then you can temporarily remove the offending package from your dependencies in package.json and try again.