This repository was archived by the owner on Apr 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
"npm login" with private Artifactory don't work with ng update. RegistryClient returns 401 #917
Copy link
Copy link
Closed
Description
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
-
You need a private Artifactory repository using
HTTPS + Basic Authentication.
-
.npmrc
Configuration
registry=https://some.local.registry
ca[]="my cert ..."
strict-ssl=false
always-auth=true
email=me@example.org
- Login via
npm login
$ npm login
Username: foo
Password: ***
E-Mail: me@example.com
- Run
ng update
It does not matter if you use ng update
or ng update xxx-package
.
- 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
- 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: #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