Skip to content

"npm login" with private Artifactory don't work with ng update. RegistryClient returns 401 #12100

Closed

Description

@alexeagle

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=me@example.org
  1. Login via npm login
$ npm login
Username: foo
Password: ***
E-Mail: me@example.com
  1. Run ng update

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

  1. 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
  1. 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: angular/devkit#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

Activity

  1. modified the milestone: needsTriage on Sep 4, 2018
  2. davidfmatheson commented on Oct 19, 2018

    @davidfmatheson

    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?

  3. clydin commented on Mar 13, 2019

    @clydin
    Member

    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.

  4. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  5. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions