pnpm: pnpm publish doesn't work with npm access token

In our company, we deploy private libraries that we have in a monorepo to the npm registry.

pnpm version: 6.32.11

Code to reproduce the issue:

To deploy new versions we use this job in GitLab.

default:
  image: node:12.22.5

before_script:
  - curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@latest-6
  - pnpm config set store-dir .pnpm-store
  - pnpm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}

stages:
  - deploy

npm-publish:
  stage: deploy
  script:
    - pnpm -r install --aggregate-output
    - pnpm -r publish --no-git-checks
  cache:
    key:
      files:
        - pnpm-lock.yaml
    paths:
      - .pnpm-store
  only:
      - master

Expected behavior:

CI pipeline should publish correctly all the libraries with new versions.

Actual behavior:

The pipeline fails asking for OTP: (Included only the error)

$ pnpm -r publish --no-git-checks
....
npm ERR! code EOTP
npm ERR! This operation requires a one-time password from your authenticator.
npm ERR! You can provide a one-time password by passing --otp=<code> to the command you ran.
npm ERR! If you already provided a one-time password then it is likely that you either typoed
npm ERR! it, or it timed out. Please try again.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-06-26T21_27_11_550Z-debug.log

To clarify, we are sure the NPM_TOKEN is correct and works because we can publish with lerna publish using the token.

Additional information:

  • node -v prints: 12.22.5
  • Windows, macOS, or Linux?: Linux/CI

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 8
  • Comments: 19 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I’m experiencing this as well. npm publish works fine, pnpm publish errors out with:

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/
npm ERR! need auth You need to authorize this machine using `npm adduser`

How should i publish?

npm publish --no-git-checks nor pnpm publish --no-git-checks works

Edit: got it working

@zkochan the auth token was generated in npm correctly, added to CI variables, and included in the env:

pnpm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}

And works perfectly as I said before because we are using it to publish with lerna right now.

Here is my working GH action for publishing:

name: πŸš€ Publish

on:
  release:
    types: [created]

jobs:
  publish-github:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write
      packages: write
    steps:
      - name: ⬇️ Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Install Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 20.x
          registry-url: https://npm.pkg.github.com/

      - uses: pnpm/action-setup@v2
        name: Install pnpm
        id: pnpm-install
        with:
          version: 8
          run_install: false

      - name: πŸ“ Version
        env:
          TAG_NAME: ${{ github.event.release.tag_name }}
        run: pnpm version ${TAG_NAME} --no-git-tag-version

      - name: πŸ™ Publish no GitHub
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: pnpm publish --no-git-checks

But pls keep your attention on the registry-url - you need a trailing slash on the end of the registry URL. Don’t ask me how I know it, but if you would ask here you’ll find the answer πŸ˜…

eventually got mine working (with a user-scoped public package) like this

      - name: Publish
        env:
          NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
        run: |
          echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
          echo "@{PUT_YOUR_SCOPE_HERE}:registry=https://registry.npmjs.org/" >> ~/.npmrc
          pnpm publish --no-git-checks --access public

For me pnpm seems to read incorrect .npmrc configuration pnpm publish will only work if i copy the project level .npmrc (which contains scope and auth token) to my ~. pnpm config list however shows correctly the project level configuration. it can distinguish between local and global with the --location flag, but it seems during publish it only uses the global configuration?

This problem still happening today πŸ˜•