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 -vprints: 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
- fix(github/release-pipeline): Set npm registry explicitly Hopefully this allows pnpm publish (aka npm publish) to properly use the npm token in AUTH_NODE_TOKEN without any additional setup. see https... — committed to wuespace/telestion by fussel178 2 years ago
- set env token https://github.com/pnpm/pnpm/issues/4937#issuecomment-1179593352 — committed to opral/monorepo by samuelstroschein 2 years ago
Iβm experiencing this as well.
npm publishworks fine,pnpm publisherrors out with: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:
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:
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
For me pnpm seems to read incorrect .npmrc configuration
pnpm publishwill only work if i copy the project level.npmrc(which contains scope and auth token) to my~.pnpm config listhowever shows correctly the project level configuration. it can distinguish between local and global with the--locationflag, but it seems during publish it only uses the global configuration?This problem still happening today π