pnpm install fails with 401/403 when registry token is expired or read-only
0 reputation · 28 Sept 2024, 03:18 UTC
0 reputation · 28 Sept 2024, 03:18 UTC
When pnpm install or pnpm publish fails against a private registry, the failure often surfaces as a generic HTTP 401 Unauthorized or 403 Forbidden relayed from the registry. Because pnpm stores npm-compatible tokens in .npmrc and does not define its own fine-grained roles beyond read-only and read-write, the output does not inherently distinguish between an expired token, a revoked token, a scope mismatch, or a transient registry outage.
Registry tokens are generally long-lived and static; pnpm does not natively enforce short-lived expiration or automatic rotation. The distinction between these failure causes remains an unresolved behavior, and it may vary across registries such as npm, GitHub Packages, Artifactory, and Verdaccio, as well as across pnpm versions. Verifying whether a credential is truly expired or merely insufficient requires consulting registry-specific documentation, since pnpm defers expiration policy entirely to the registry.
Is there a documented pnpm mechanism or registry convention that clarifies whether a 401/403 during install indicates a credential rotation requirement rather than a network or registry-side issue? How should teams configure token lifecycles when pnpm defers expiration policy entirely to the registry? What diagnostic signals are available to separate scope-insufficient read-only tokens from expired credentials without relying on registry-specific error payloads?
35275 reputation · 28 Sept 2024, 09:23 UTC
When pnpm install or pnpm publish returns an HTTP 401 Unauthorized or 403 Forbidden, the problem almost always lies in the credentials that pnpm sends to the registry. pnpm itself does not distinguish between an expired token, a revoked token, or a token that lacks the necessary scope – it simply forwards the token stored in .npmrc or supplied via an environment variable. The only way to tell whether the failure is due to expiration, insufficient permissions, or a transient registry outage is to look at the full response body that the registry returns.
.npmrc using the format //registry.example.com/:_authToken=YOUR_TOKEN.--verbose, which can be used to capture the body.pnpm config get //registry.example.com/:_authToken
If the output is empty, the token is missing and you need to add it to .npmrc or set the PNPM_AUTH_TOKEN environment variable.
curl -H "Authorization: Bearer $(pnpm config get //registry.example.com/:_authToken)" \
https://registry.example.com/-/v1/package/your-package
Inspect the JSON body of the response. A message like "token expired" or "Bad credentials" indicates expiration; a message about missing permissions indicates a scope issue.
pnpm install --verbose
Look for the error or message fields in the logged response.
.npmrc or the CI secret.
PNPM_AUTH_TOKEN).read:packages for installs, write:packages for publishes).To give a more precise recommendation, could you share the exact body that the registry returned with the 401/403? If the body is empty or generic, the issue may be a transient network problem rather than a credential problem.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.