This command requires you to be logged in

UPDATE/TLDR: There is a bug in npm. With node:16-buster I was able to publish a local tgz file.

.npmrc :

registry=https://gitlab.com/api/v4/projects/<redacted project id>/packages/npm/
//gitlab.com/api/v4/projects/<redacted project id>/packages/npm/:_authToken=<pers auth token>

Docker: docker run -it --rm -v ${pwd}\.npmrc:/app/.npmrc -v ${pwd}\packages:/app/packages -w /app node:16-buster sh1

# node -v
v16.14.0
# npm -v
8.3.1

Publish: npm publish ./packages/zone.js-0.11.3.tgz --tag zone.js@0.11.3 --userconfig /app/.npmrc --registry https://gitlab.com/api/v4/projects/<redacted project id>/packages/npm/

ORIGINAL POST…

I am working on replicating a specific package/node_modules to ensure our builds (which are tied to very specific versions) succeed.

Of the 1250 packages, I was able to get 1220 published to my (hosted) Gitlab project I setup to host the packages. However, there are a consistent number (about 20) that despite the same .npmrc registry settings… they act as though the credentials havent been supplied via .npmrc

Example command,

npm publish ./packages/angular-animations-11.2.0.tgz --tag @angular/animations@11.2.0

Which ends with…

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\<redacted>\AppData\Local\npm-cache\_logs\2022-02-27T03_53_30_034Z-debug.log

I had a strange issue for awhile (which I think I finally resolved by removing the “node_modules” for the project I am working on) where…

npm config get

…would list conflicting auth settings in ./.npmrc that were not there!

PS: I did follow the Gitlab docs on setting up auth (at least, I believe so)

PPS: I also found this issue already files that seems to be relevant and amounts to a breaking change in node/npm.

PPPS: Gitlab issue linked above points to https://github.com/npm/cli/issues/2453 in which this comment claims that specifying the target --registry works,

Using Docker/node 16, //registry:_authToken= in npmrc, and --userconfig and --registry on command line worked.

1 Like

However, it currently cant override packages with publishConfig defined in the package.json (noted here)