Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing NPM module to github packages registry from Github Actions?

My YML so far, kept adding bits based on other stackoverflow threads + docs:

name: Node install, build and test

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x]
    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Create NPMRC
        run: echo "//registry.npmjs.org/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN}}
      - name: Publish to Github Packages
        run: |
          npm config set _auth $NODE_AUTH_TOKEN
          npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN}}

In my package.json I have:

  "publishConfig": {
    "registry": "https://npm.pkg.github.com/"
  },

And with the above config I keep getting

E400 Bad Request
Your request could not be authenticated by the Github Pacakges service. Please ensure your access token is valid and has the appropriate scopes configured.
like image 713
SebastianG Avatar asked May 15 '26 02:05

SebastianG


1 Answers

You are writing the wrong content to the ~/.npmrc file.

It should be //npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }} but you are doing //registry.npmjs.org/:_authToken=${{ secrets.GITHUB_TOKEN }}

like image 52
manojlds Avatar answered May 19 '26 09:05

manojlds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!