Github actions: NPM publish 404 not found

Viewed 3050

In my github project Im trying to automatically create a new version and publish it to NPM whenever something is pushed to the master branch.

The idea

  1. Create a new minor version
  2. Publish the package to NPM

Im using github actions. My workflow file looks like this:

# This workflow will run tests using node and then publish a package to the npm registry when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Node.js Package

on:
#trigger on every commit to the main branch
  push:
    branches:
      - main
      - master 

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - run: npm test

  publish-npm:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://registry.npmjs.org/
      - run: git config user.name $GITHUB_ACTOR
      - run: git config user.email gh-actions-${GITHUB_ACTOR}@github.com
      - run: git remote add gh-origin https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
      - run: echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> ~/.npmrc
      - run: npm version patch
      - run: npm publish
      - run: git push gh-origin HEAD:master --tags
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

(https://github.com/ether/ep_align/actions/runs/322527776)

I keep getting a 404 error when doing the publish. Which I dont' understand because the package is online here: https://www.npmjs.com/package/ep_align

npm ERR! code E404
npm ERR! 404 Not Found - PUT https://registry.npmjs.org/ep_align - Not found
npm ERR! 404 
npm ERR! 404  'ep_align@0.2.7' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

This problem is driving me nuts for a few hours now, and I have no idea what it could be. Any ideas?

1 Answers

it is just an authentication issue with your token.

Have you ever set the access token in your Repository secrets ? (You might want to create environments as well.)

https://docs.npmjs.com/creating-and-viewing-access-tokens

Or it might be an issue with authorization as well. Please check your token type. It should be automation one.

Here is an example from me > https://github.com/canberksinangil/canberk-playground

Where I have set my token under the repository settings. enter image description here

Let me know if this helps :)

Related