Npm publish required me to be logged in when I am logged in

Viewed 1309

Hi i got problems with deploying my npm package. First of all I deployed it manually by type npm publish everything worked, package was published. But I wanted it to be published every time i push changes on main. So I add that commands to my github actions CI config

      - name: Run build
        run: yarn build

      - name: Publish to npm
        run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

And it publishing that package on github packages but not on npm. I tried to publish it manually but i got that error npm

$ npm publish

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\makow\AppData\Local\npm-cache\_logs\2021-11-02T14_22_20_432Z-debug.log
1 Answers

Your GITHUB_TOKEN is your token for GitHub, not npm. The solution is to get an npm token valid for publication, add it as a GitHub secret, and make it available to your GitHub Actions workflow.

Given your layout, it looks like you are trying to use release-please but you are using your GitHub token rather than an npm token. Follow the instructions in the npm docs to create a token and add it as a secret in your repo. Then update your workflow to access that secret. (You'll still need the GitHub token too to publish to GitHub and probably to do other things.)

Related