Angular-cli: "npm login" with private Artifactory don't work with ng update. RegistryClient returns 401

Created on 5 Sep 2018  路  3Comments  路  Source: angular/angular-cli

_From @BaggersIO on May 15, 2018 12:46_

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Area

- [ ] devkit
- [x] schematics

Versions

$ node --version
8.11.1

$ npm --version
5.6.0

Operating System: Windows 7

Repro steps

1) You need a private Artifactory repository using HTTPS + Basic Authentication.

2) .npmrc Configuration

registry=https://some.local.registry
ca[]="my cert ..."
strict-ssl=false
always-auth=true
[email protected]

3) Login via npm login

$ npm login
Username: foo
Password: ***
E-Mail: [email protected]

4) Run ng update

It does not matter if you use ng update or ng update xxx-package.

5) CLI / RegistryClient throws 401 for GET http://some.local.registry/...

The ng update command stops after a few minutes (~2-3 mins) without any exception.

I digged deeper into the update schematic at npm.js with few logs and got this:

{ Error: Registry returned 401 for GET on https://some.local.registry/artifactory/api/npm/npm-virtual/karma
聽 聽 at makeError (C:\dev\shared\node_modules\npm-registry-client\lib\request.js:316:12)
聽 聽 at RegClient.<anonymous> (C:\dev\shared\node_modules\npm-registry-client\lib\request.js:292:14)
聽 聽 at Request._callback (C:\dev\shared\node_modules\npm-registry-client\lib\request.js:216:14)
聽 聽 at Request.self.callback (C:\dev\shared\node_modules\request\request.js:188:22)
聽 聽 at emitTwo (events.js:126:13)
聽 聽 at Request.emit (events.js:214:7)
聽 聽 at Request.<anonymous> (C:\dev\shared\node_modules\request\request.js:1171:10)
聽 聽 at emitOne (events.js:116:13)
聽 聽 at Request.emit (events.js:211:7)
聽 聽 at IncomingMessage.<anonymous> (C:\dev\shared\node_modules\request\request.js:1091:12) pkgid: 'karma', statusCode: 401, code: 'E401' } { errors: [ { status: 401, message: 'Authentication is required' } ] }
Registry returned 401 for GET on https://some.local.registry/artifactory/api/npm/npm-virtual/karma

6) Quick and Dirty Hack to get it working

Since npm login has no effect, I had to patch npm.js in the update schematic to get it working:

const client = new RegistryClient({
    proxy: {
        http: options[0],
        https: options[1],
    }, ssl: {
        strict: false, // This was needed but it is still fixed
    }
});
client.log.level = 'silent';
const params = {
    timeout: 30000,
    auth: { // This was needed for authentication
        alwaysAuth: true,
        username: 'my_usenrame', // My artifactory username
        password: 'my_encrypted_password' // My encrypted password
    }
};

https://github.com/angular/devkit/blob/master/packages/schematics/update/update/npm.ts#L100-L116

Note: the strict-ssl patch is not needed anymore: https://github.com/angular/devkit/pull/838

With the hack above my ng update command worked well.

The log given by the failure

I logged out the following exception:

{ Error: Registry returned 401 for GET on https://some.local.registry/artifactory/api/npm/npm-virtual/karma
聽 聽 at makeError (C:\dev\shared\node_modules\npm-registry-client\lib\request.js:316:12)
聽 聽 at RegClient.<anonymous> (C:\dev\shared\node_modules\npm-registry-client\lib\request.js:292:14)
聽 聽 at Request._callback (C:\dev\shared\node_modules\npm-registry-client\lib\request.js:216:14)
聽 聽 at Request.self.callback (C:\dev\shared\node_modules\request\request.js:188:22)
聽 聽 at emitTwo (events.js:126:13)
聽 聽 at Request.emit (events.js:214:7)
聽 聽 at Request.<anonymous> (C:\dev\shared\node_modules\request\request.js:1171:10)
聽 聽 at emitOne (events.js:116:13)
聽 聽 at Request.emit (events.js:211:7)
聽 聽 at IncomingMessage.<anonymous> (C:\dev\shared\node_modules\request\request.js:1091:12) pkgid: 'karma', statusCode: 401, code: 'E401' } { errors: [ { status: 401, message: 'Authentication is required' } ] }
Registry returned 401 for GET on https://some.local.registry/artifactory/api/npm/npm-virtual/karma

Desired functionality

npm login / authentication + private Artifactory works with ng update

Mention any other details that might be useful

_Copied from original issue: angular/devkit#917_

schematicupdate bufix

Most helpful comment

I'm seeing this, too.

$ node -v
v10.12.0

$ npm -v
6.4.1

Operating System: OS X High Sierra

@alexeagle could you please elaborate a bit more on the work-around for someone who just has npm and angular-cli installed locally?

All 3 comments

I'm seeing this, too.

$ node -v
v10.12.0

$ npm -v
6.4.1

Operating System: OS X High Sierra

@alexeagle could you please elaborate a bit more on the work-around for someone who just has npm and angular-cli installed locally?

This should be corrected in the latest CLI version (7.3.5). If the problems still persists, please open a new issue with updated environment and version information.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings