question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

publishing to npm fails after publishing to GPR

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:36 (5 by maintainers)

github_iconTop GitHub Comments

39reactions
tjansoncommented, Sep 16, 2019

@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

registry=https://registry.npmjs.org/
@tjanson:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}

In the workflow config, I don’t use any with: arguments for the Node setup (except node-version: '10.x'), and I set a personal access token (as secret) for the NODE_AUTH_TOKEN env var (I think the GITHUB_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.

24reactions
nkzawacommented, Sep 4, 2019

I also had the same issue, and fixed by creating ~/.npmrc like:

- run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" > ~/.npmrc
- run: npm publish
Read more comments on GitHub >

github_iconTop Results From Across the Web

getting not found error when trying to publish package to npm
I'm trying to publish a new package to npm, public. I have the following workflow: # This workflow will run tests using node...
Read more >
How to publish an npm package to npm and GitHub Package ...
The first is to build the project. The second is to publish to npm, and the third is to publish to GitHub Package...
Read more >
npm-publish | npm Docs
The publish will fail if the package name and version combination already exists in the specified registry. Once a package is published with...
Read more >
NPM Publish to GPR and NPM | Mitchell Simoens Blog
I've seen a few blogs about publishing a node module to the NPM repository and GitHub Package Registry (GPR). Some I like, some...
Read more >
How to publish NuGet packages | Microsoft Learn
nupkg file, run the following command. Specify your .nupkg filename, and replace the key value with your API key. .NET CLI Copy.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found