Hello everyone I am trying to publish my NPM package to GitHub packages using this yaml:
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Node.js Package (GHP)
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm test
publish-gpr:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
But I am getting this error which I don't really understand since this is a template by GitHub themselves.
Here You can find my package.json.
I also tried adding a .npmrc file but my workflow still doesn't work.
I am really hoping you guys can help me with this issue. (My publish to NPM workflow works just fine btw, I just can't seem to get it to work with GitHub Packages)
Edit: My NPM account is also linked with GitHub.
ENEEEDAUTHerror while trying to publish an NPM package to GitHub Packages, it typically indicates an authentication issue (as illustrated bynpm/cliissue 6184).If this does not apply, the rest of your GitHub Actions workflow seems correctly set up for publishing to GitHub Packages, with the
NODE_AUTH_TOKENenvironment variable being correctly assigned tosecrets.GITHUB_TOKEN.The
.npmrc(Roo7K1d:registry=https://npm.pkg.github.com) (before you deleted it) tried to associate your package scope with GitHub's npm registry. However, for it to work correctly, you need to make sure that the scope in yourpackage.jsonmatches the username or organization name on GitHub exactly and is correctly referenced in.npmrc. For GitHub Packages, the correct format usually includes the scope, like:And your
package.jsonname field should include the scope as well:That is important for GitHub Packages because it uses the scope to route the package to your account. Your
publishConfigsection seems correctly set, but make sure the scope is included in your package name.Double-check that your GitHub token has the appropriate permissions for package publication.