setup-node: publishing to npm fails after publishing to GPR
I have a workflow like this that’s supposed to publish to npm once I publish to GPR:
name: Publish to npm
on: registry_package
jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm install && npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
I have the npm_token
secret added to this repository.
When I just published to GPR, it kicked off this workflow job, but it failed at the last step of publishing to npm. The error was from npm saying:
npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"
What does this error mean, and how do I fix it? I don’t see anything about setting “basic realm” in the recipes for this setup-node
action.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 16
- Comments: 38 (5 by maintainers)
Links to this issue
Commits related to this issue
- Add authToken to npmrc Setting the `NODE_AUTH_TOKEN` environment variable doesn't seem to work, trying an npmrc file instead. https://github.community/t5/GitHub-Actions/Installing-npm-packages-fro... — committed to Workgrid/workgrid-javascript by TuckerWhitehouse 5 years ago
- workflow: use actions/setup-node Use actions/setup-node as actions/npm is apparently deprecated and exits 1: https://github.com/wmde/vuex-helpers/runs/254025692 Publishing (a scoped package) may or ... — committed to wmde/vuex-helpers by wiese 5 years ago
- workflow: use actions/setup-node Use actions/setup-node as actions/npm is apparently deprecated and exits 1: https://github.com/wmde/vuex-helpers/runs/254025692 It's a win that this now references a ... — committed to wmde/vuex-helpers by wiese 5 years ago
- workflow: use actions/setup-node Use actions/setup-node as actions/npm is apparently deprecated and exits 1: https://github.com/wmde/vuex-helpers/runs/254025692 It's a win that this now references a ... — committed to wmde/vuex-helpers by wiese 5 years ago
- workflow: use actions/setup-node Use actions/setup-node as actions/npm is apparently deprecated and exits 1: https://github.com/wmde/vuex-helpers/runs/254025692 It's a win that this now references a ... — committed to wmde/vuex-helpers by wiese 5 years ago
- workflow: use actions/setup-node Use actions/setup-node as actions/npm is apparently deprecated and exits 1: https://github.com/wmde/vuex-helpers/runs/254025692 It's a win that this now references a ... — committed to wmde/vuex-helpers by wiese 5 years ago
- workflow: use actions/setup-node Use actions/setup-node as actions/npm is apparently deprecated and exits 1: https://github.com/wmde/vuex-helpers/runs/254025692 It's a win that this now references a ... — committed to wmde/vuex-helpers by wiese 5 years ago
- Trying fix Trying fix from https://github.com/actions/setup-node/issues/52 — committed to yukipastelcat/chronometric by yukipastelcat 4 years ago
- Fix npm registry https://github.com/actions/setup-node/issues/52#issuecomment-527826020 — committed to nextcloud-libraries/eslint-config by skjnldsv 4 years ago
- Fix npm publish, use solution suggested here https://github.com/actions/setup-node/issues/52 — committed to lensapp/lens-platform-sdk by chenhunghan 3 years ago
- Merge pull request #52 from akamai/versionBump version bump — committed to krzyk/setup-node by bradforj287 5 years ago
@pqt Just to be clear: You’re talking about publishing to GitHub Package Registry only (not the npmjs.org registry)? Because I’ve got that working from within GitHub Actions, with this
.npmrc
In the workflow config, I don’t use any
with:
arguments for the Node setup (exceptnode-version: '10.x'
), and I set a personal access token (as secret) for theNODE_AUTH_TOKEN
env var (I think theGITHUB_TOKEN
would also work).Is that what you’re trying to accomplish or am I totally misunderstanding you?
PS: That
.npmrc
is in the repo root, not at~/.npmrc
. Simply commited that file.I also had the same issue, and fixed by creating
~/.npmrc
like:Hi all - here is a workflow that publishes to both NPMJS and GPR, without needing .npmrc workarounds:
Just replace
<@OWNER>
with appropriate scope (eg for me it would be@affrae
), and use your version ofnpm_token
Is working at https://github.com/affrae/fib-tools
Publishing to GPR from Actions (what @pqt seems to be doing) and publishing to NPM from Actions (which, in my case, is triggered after first publishing to GPR) are separate topics.
However, they both seem to have the same symptom, which is that the Action doesn’t seem to apply the correct credentials for the publishing (from npm secrets), and/or Actions is not properly using the “registry” setting from the Action. In some cases you can “hack” around this problem by just forcing your own .npmrc, but that’s both a hack and runs contrary to the published documentation for this Action, so it shouldn’t be “the solution”.
In my case, since my project already has a npmrc in it, to redirect the initial publish to GPR in the first place, I do not think it’s a suitable solution to somehow hack or override that npmrc during the Action to then redirect to npm.
This is a blocker for me to using Github Actions. I would really appreciate some more info on it.
OK, I think I have finally cracked this problem.
I updated my workflow action YAML to have this npm-publish:
That flag has the effect of overriding what’s in the local .npmrc that redirected the original publish to GPR, so that actions can now publish to regular npm.
I think because this is a scoped package, adding the scope parameter should do the trick. So:
I’m not 100% sure how this will interact with a repo that has a
.npmrc
file already, but I think it should be fineI found the solution for this @getify You basically need to publish your package as private
I doubt others will be in such a specific situation as I was, especially given now that github owns npm and will probably more closely integrate the two. I expect eventually this is a non-issue. Closing for now.
Not sure if this helps, I was also running into this… I was just missing the
@org-name
from thename
. Also, thepublishConfig
is the alternative to using the.npmrc
; which I understand you don’t want to do.So your package.json would look like this:
https://help.github.com/en/github/managing-packages-with-github-package-registry/configuring-npm-for-use-with-github-package-registry#configuring-a-package-scope-using-a-local-npmrc
Only add
repository
if I want to have the package name to be different from repo.Hope that helps.
I didn’t try
npm config
commands – interesting idea – but I did essentially configure npm via command-line flags, as mentioned in this comment: https://github.com/actions/setup-node/issues/52#issuecomment-536544414Yeah, I see the difference now that you mention that @getify.
To clarify, my current situation is just trying to publish to GPR at all, which has proven to be unsuccessful out of the gates. I’ll stay subscribed to the thread but our approaches seem to be different enough that it might warrant a separate issue entirely.
Not sure that this adds much to the conversation but through the grapevine of (limit) google results and community searching, this has turned into a show-stopper for using Actions and GPR.
I’m getting the exact same errors as described above.
Repo in question is https://github.com/paquette/react-components
Using the CLI I can publish to GPR no problem, but the authentication fails with Actions – even though the process is nearly identical and as far as I can tell it’s hooked up as documentation suggests.
The failing PR (and their associated checks) can be found in this PR https://github.com/paquette/react-components/pull/7
According to the examples provided for this repo for publishing to npm, presumably the
with: registry_url: ..
is supposed to be taking the place of a local npmrc, and I would also assume theNODE_AUTH_TOKEN
environment variable is either something that this action uses or that the npm client itself uses.The approach of
echo
ing out an npmrc is not only hacky but also seems a bit dangerous given that we already have to have an npmrc in the repo to publish to GPR in the first place, which means effectively thisecho
is overwriting the file just before publish.I am really not a pro, but it seems you are trying to publish to github packages, and in your .npmrc you have :
Could this be the problem ?
Hi All, I have another solution. Only the
package.json
registry would work, and the bash registry setting doesn’t work on GPR publishing! So I copied the registry onpackage.json
right before publishing! May you look at this gist please! 🙃@phillmac - can create a separate issue for your failure. I think I may know it is and looks to be different than the issue from @getify - I’ll follow up on that issue
This npm parameter can force the CLI tool to use a specific .npmrc file, so I think that’s the best fix here:
https://docs.npmjs.com/misc/config#userconfig
The sticky part is, I could do that manually in my
npm publish
command, but then I’m hard-coding a specific path that I don’t control (decided by this setup-node script), which means if this script sometime later decides to put the .npmrc in a different location, my builds start breaking.So perhaps setup-node could create a .npmrc file in a location, and export whatever path that is as another environment variable, like NPMRC_PATH, and then my script could say:
I think that would fix the issue here in the most reasonable way.
Perhaps setup-node should not be relying on an npmrc for this config, and should instead inject the
--registry=..
parameter (along with a shell reference to theNODE_AUTH_TOKEN
env variable) into mynpm install
command?I have the same problem trying to publish a package to private gemfury - the secrets/NODE_AUTH_TOKEN environment variable is not working correctly. I suspect its being overwritten with XXXXX-XXXXX-XXXXX-XXXXX but its hard to debug
https://github.com/actions/setup-node/blob/master/src/authutil.ts
adding these run commands to publish-npm helps a little