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.

Unable to publish to the GitHub Registry

See original GitHub issue

I’ve been following this document (and the README): https://github.community/t5/GitHub-Actions/bd-p/actions, specifically the part about cross publishing between npmjs and the GitHub registry, but I can’t seem to get it to work. This is my workflow: https://github.com/JamesIves/github-pages-deploy-action/blob/dev/.github/workflows/publish.yml

The problem I’m having is that every time I publish it says I must authenticate, except it’s providing a URL related to the npmjs registry: 401 Unauthorized - PUT https://registry.npmjs.org/github-pages-deploy-action - You must be logged in to publish packages.

This is the full log. Am I missing something here or is this a bug?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:15
  • Comments:22 (2 by maintainers)

github_iconTop GitHub Comments

21reactions
JamesIvescommented, Sep 11, 2020

I’ve managed to resolve this with my actions with the following workflow file:

https://github.com/JamesIves/github-pages-deploy-action/blob/dev/.github/workflows/publish.yml

I also added the scope to the package.json file here: https://github.com/JamesIves/github-pages-deploy-action/blob/dev/package.json#L2

It now cross publishes between npm and GitHub correctly. Thanks to everyone for their help resolving this. I’ll leave this open as I still believe this is an issue with setup-node.

2reactions
jojobytecommented, Jun 2, 2022

My repo was having a similar issue to this one. Replacing the package name in package.json by adding the scope to it solved it for Github Package Registry.

// original
{
    "name": "traefikjam",
}

// fix for GPR publish
{
    "name": "@jojobyte/traefikjam",
}

My fix: https://github.com/jojobyte/traefikjam/blob/master/.github/workflows/node-build.yml#L40

jobs:
  npm-build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18.x'
          registry-url: 'https://registry.npmjs.org'
      - run: npm ci
      - name: Publish to NPM
        run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
      - uses: actions/setup-node@v3
        with:
          node-version: '18.x'
          registry-url: 'https://npm.pkg.github.com'
          scope: '@scope'
      - run: npm ci
      - name: Publish to GitHub Package Registry
        run: |
          sed -i 's+"name": ".*+"name": "@${{ github.repository }}",+gI' ./package.json
          npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

This lets you publish to NPM with an unscoped package name and GPR with a scoped package name.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to publish to GitHub Package Registry · Issue #53
I use the workflow you suggest, but the npm publish action on GitHub Package Registry doesn't work. On npmjs it works.
Read more >
Unable to publish Github package #269
I am trying to setup a workflow that publishes a Github package, but I can't seem to make it work. ... But the...
Read more >
Unable to publish unscoped packages to the ... - GitHub
The npm publish step in the above workflow fails with the following error: npm ERR! 401 Unauthorized - PUT https://npm.pkg.github.com/@remarkjs/ ...
Read more >
Publishing to github registry fails · Issue #437 · sindresorhus/np
Description I just received access to the github package registry. When trying to use np it fails in the prerequisite stage: ❯ Prerequisite ......
Read more >
Unable to publish private package · Issue #739 - GitHub
npmrc file then I get the same error running npm info locally. npm ERR! code E404 npm ERR! 404 Not Found - GET...
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