Publish still doesn't work after successful login
Hi there, i'm trying to login to my private npm registry. The login seems to work according to my logs, but npm publish still thinks I'm not logged in.
my action just executes the following commands:
npm install -g npm-cli-login
npm config set registry https://nexus.mycompany.com/repository/npm-hosted/
npm-cli-login -u ${{ secrets.NEXUS_USER }} -p ${{ secrets.NEXUS_PASSWORD }} -e [email protected] -r https://nexus.mycompany.com/repository/npm-hosted/
npm publish --registry https://nexus.mycompany.com/repository/npm-hosted/
and the result is
Run npm install -g npm-cli-login
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
added 105 packages, and audited 106 packages in 4s
5 packages are looking for funding
run `npm fund` for details
2 high severity vulnerabilities
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
info attempt registry request try #1 at 8:37:38 AM
http request PUT https://nexus.mycompany.com/repository/npm-hosted/-/user/org.couchdb.user:***
http 201 https://nexus.mycompany.com/repository/npm-hosted/-/user/org.couchdb.user:***
...
npm notice
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://nexus.mycompany.com/repository/npm-hosted/
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! /home/runner/.npm/_logs/2022-07-04T08_37_38_852Z-debug-0.log
Error: Process completed with exit code 1.
Although we see that the login did succeed, the npm publish command seems to fail, due to lack of authentication
Is there something I'm doing wrong?
regards, patrick
Same problem 🫠
When NPM_REGISTRY variable is set to e.g. https://nexus.mycompany.com/repository/npm-hosted npm-cli-login adds the following line in $HOME/.npmrc
//mycompany.com/repository/npm-hosted/:_authToken=NpmToken.00000000-0000-0000-0000-000000000000
while regular interactive npm login --repository https://nexus.mycompany.com/repository/npm-hosted the following one
//mycompany.com/repository/:_authToken=NpmToken.00000000-0000-0000-0000-000000000000
and with the latter npm publish works as expected. Just my two pennyworth, actually I have near-zero experience with the NPM ecosystem and just've stumbled on the issue.
I have workaround for this problem.
npm-cli-login automatically add slash to end of registry url. When do you pass argument r with slash on the end of registry url, it creates a slash duplication in .npmrc. Such duplication causes non-functionality of npm authorization.
Remove the last slash in the registry url and it will work perfectly.
Output example:
# Bad
$ npm-cli-login -u user -p pass -e [email protected] -r https://artifactory.bar.org/artifactory/api/npm/private-registry/
$ cat ~/.npmrc
//artifactory.bar.org/artifactory/api/npm/private-registry//:_authToken=xYz…
# Good
$ npm-cli-login -u user -p pass -e [email protected] -r https://artifactory.bar.org/artifactory/api/npm/private-registry
$ cat ~/.npmrc
//artifactory.bar.org/artifactory/api/npm/private-registry/:_authToken=xYz…
That works for me, thank you very much @lkudry!