Skip to content

docs(npmrc): describe how credentials are matched to the registry URL - #10107

Open
ump45nose wants to merge 2 commits into
npm:latestfrom
ump45nose:contrib-fix-3618
Open

ump45nose wants to merge 2 commits into
npm:latestfrom
ump45nose:contrib-fix-3618

Conversation

@ump45nose

Copy link
Copy Markdown

Adds a "How npm matches a credential to a registry" subsection to configuring-npm/npmrc.md.

It documents the lookup implemented in npm-registry-fetch (lib/auth.js, regFromURI): starting from //host[:port]/path of the registry URL, npm walks up the path until it finds a key with credentials, so host-level and shorter-path keys apply, while a different host or port never matches. It also notes that a non-matching key surfaces as ENEEDAUTH / "This command requires you to be logged in" (lib/utils/get-identity.js, lib/commands/publish.js), the same error as having no credentials at all.

Scope: documentation only. This does not fix #3618 (the error message itself remains obscure); it just explains the matching rules so the error is easier to diagnose. Refs #3618 — the issue should stay open for an error-message improvement if you want one.

No tests run (docs only).

AI assistance disclosure: this change was prepared with the help of an AI coding agent (Grok Bot). The account owner has not reviewed every line in detail; please treat it accordingly.

The auth keys `_authToken`, `_auth`, etc. are looked up by registry URI with an
exact string match, but nothing in the docs said so. A scope that differs from
the registry URL by a single trailing slash or a port is simply a different key,
so npm finds no credentials at all and commands that need to log in fail with
ENEEDAUTH and the generic "This command requires you to be logged in" message -
the same message shown when no credentials were ever configured.

Add a subsection to the auth configuration section explaining the exact-match
rule, that a host-level scope is not a fallback for a path on that host, and
that the ENEEDAUTH message is misleading in this case because the token is
present but keyed to a non-matching URI. It also documents how to check which
key npm actually resolved with `npm config get` and `npm config ls -l`.

Closes: npm#3618
@ump45nose
ump45nose requested a review from a team as a code owner October 10, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] npmrc errors related to lacking authToken are obscure

1 participant