Skip to content

fix: improve unknown config warning with .npmrc section hint#8995

Merged
wraithgar merged 4 commits intonpm:latestfrom
umeshmore45:fix/improve-unknown-config-warning
Feb 19, 2026
Merged

fix: improve unknown config warning with .npmrc section hint#8995
wraithgar merged 4 commits intonpm:latestfrom
umeshmore45:fix/improve-unknown-config-warning

Conversation

@umeshmore45
Copy link
Contributor

Why / What

Fixes #8153

When npm 11.2.0 introduced unknown config key warnings, the message gave
users no actionable guidance:

Before:

npm warn Unknown user config "electron_mirror". This will stop working 
in the next major version of npm.

Users were left confused — no hint on what to do instead.

After:

npm warn Unknown user config "electron_mirror". This will stop working 
in the next major version of npm. To pass package-specific config, use 
a scoped [sectionName] in .npmrc. See `npm help npmrc`.

The hint is intentionally omitted for --cli flag sources since CLI
flags are unrelated to .npmrc syntax.

Changes

  • workspaces/config/lib/index.js — Improved warning message in
    checkUnknown() with actionable .npmrc section hint
  • docs/lib/content/configuring-npm/npmrc.md — Added "Custom /
    third-party config keys" section with migration examples
  • Updated test assertions and snapshots to match new warning text

What was NOT changed

  • No core config-loading logic modified
  • No new dependencies added
  • CLI-source (--flag) warnings unchanged — hint not applicable there

References

Fixes #8153

Fixes npm#8153

When npm warns about unknown user/project/env config keys, the message
now includes a hint about using [section] syntax in .npmrc for
package-specific config (e.g. electron_mirror, sass_binary_site).

The hint is omitted for --cli flags since they are unrelated to .npmrc.
custom_dir={{ version }}
```

Section headers are ignored by npm's config loader, so they will not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works by accident and in the future we hope to have sections work for things like per-command config. As such this is not something we should be recommending in the npmrc file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback @wraithgar!

Understood — I'll remove the [section] recommendation.

Could you suggest what we should recommend instead?
Should users:

  1. Use environment variables (ELECTRON_MIRROR=...)
  2. Simply remove unknown keys from .npmrc
  3. Something else?

Happy to update the docs accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original version of this you submitted without the ini sections seemed fine to me, it covered the bases and felt like you'd read all of the other responses. config in package.json, environment variables, -- separation.

I don't believe there is a current analog to the config section in package.json for npmrc, and that is something we can look into going forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wraithgar Updated as per your feedback, removed the [section]
recommendation and the ini code block. Only kept the warning
explanation and environment variables approach. Let me know if
anything else needs changing!

Copy link

@SchroederSteffen SchroederSteffen Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for nitpicking, but could you please update the PR description and also remove the sections recommendation there? I was a bit confused at first.

(By the way, I will miss this convenient config option.)

You can set these values as environment variables instead:

```bash
export ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past these example domains have been vectors for people to squat on them and claim a vulnerability. We try our best now to only use domains that npm itself owns, even in examples.

Can we change the example domains here to be something like mirrorexample.npmjs.org?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wraithgar Updated! Changed example domain to mirrorexample.npmjs.org

exports[`test/lib/commands/config.js TAP config list with publishConfig local > warns about unknown config 1`] = `
Array [
"Unknown publishConfig config /"other/". This will stop working in the next major version of npm.",
"Unknown publishConfig config /"other/". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See \`npm help npmrc\`.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still recommending ini section here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wraithgar Thanks for the feedback! Made all the changes:

  • Removed the [sectionName] hint from the warning message
  • Updated it to just say "See npm help npmrc for supported config options."
  • Removed the ini [section] recommendation from docs
  • Fixed the example domain to mirrorexample.npmjs.org
  • All tests and snapshots updated (108 suites passing)

Let me know if anything else needs tweaking!

@wraithgar
Copy link
Member

I think this is ok to land, thanks for sticking with it.

@wraithgar wraithgar merged commit 9fac412 into npm:latest Feb 19, 2026
38 checks passed
@github-actions github-actions bot mentioned this pull request Feb 19, 2026
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.

"Unknown user/project config" warnings starting in npm 11.2.0

3 participants

Comments