{{ message }}
fix(config): make prefer-offline and prefer-online exclusive#9129
Merged
wraithgar merged 3 commits intoMar 18, 2026
Merged
Conversation
When both prefer-offline and prefer-online are set to true in config, npm silently prioritizes prefer-offline without any indication to the user. This causes commands like npm view to return stale cached data with no warning. Add a conflict detection check during config load that emits a warning when both flags are active, telling the user which flag takes precedence. Fixes npm#9113
2 tasks
Contributor
Instead of a one-off if check in the config load loop, use the existing exclusive property on config definitions to mark prefer-offline and prefer-online as mutually exclusive. This matches the established pattern used by before/min-release-age, expect-results/expect-result-count, and the save-* flags. Fixes npm#9113
Contributor
Author
|
Updated - moved to |
wraithgar
reviewed
Mar 18, 2026
| }) | ||
|
|
||
| t.test('warn when both prefer-offline and prefer-online are set', async t => { | ||
| t.test('error when both prefer-offline and prefer-online are set', async t => { |
Contributor
There was a problem hiding this comment.
we don't need a test for config settings. We have tests that make sure that exclusive works but it doesn't make a lot of sense to add tests for each thing we've added an exclusive tag for. The config is the config.
Contributor
Author
There was a problem hiding this comment.
Makes sense - I'll remove the test. The exclusive mechanism is already covered generically so a per-field test is redundant.
The exclusive mechanism is already tested generically. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
wraithgar
approved these changes
Mar 18, 2026
wraithgar
approved these changes
Mar 18, 2026
Contributor
Author
owlstronaut
added a commit
that referenced
this pull request
Mar 24, 2026
owlstronaut
added a commit
that referenced
this pull request
Mar 24, 2026
owlstronaut
added a commit
that referenced
this pull request
Mar 24, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds a warning when both
prefer-offlineandprefer-onlineare set totruein config, telling the user thatprefer-offlinetakes precedence.Why this matters
When both flags are active, npm silently prioritizes
prefer-offline, causing commands likenpm view <package> versionto return stale cached data with no indication thatprefer-onlineis being ignored (#9113). Users end up debugging registry connectivity, token issues, or package naming when the actual problem is a config conflict.Changes
workspaces/config/lib/index.js: After all config sources are loaded, check if bothprefer-offlineandprefer-onlineare truthy. If so, emit a warning viaqueueWarning()so it follows the standard warning lifecycle.workspaces/config/test/index.js: Added test that passes both--prefer-offlineand--prefer-onlinevia CLI args and verifies the warning is emitted.Testing
config Both prefer-offline and prefer-online are set. prefer-offline takes precedence.Fixes #9113
This contribution was developed with AI assistance (Claude Code).