You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Silent conflict when both prefer-offline=true and prefer-online=true are set, causing npm view to return stale cached data #9113
When both prefer-offline=true and prefer-online=true are set in the .npmrc configuration, npm silently prioritizes prefer-offline. Commands that query the registry, such as npm view version, skip the network request entirely and return stale cached data. The CLI provides no warning or error message indicating that these mutually exclusive flags are conflicting or that prefer-online is being ignored.
Expected Behavior
npm should detect when mutually exclusive flags like prefer-offline and prefer-online are active simultaneously. It should either output a clear warning message to the console (e.g., WARN config: mutually exclusive flags prefer-offline and prefer-online detected) so the user is aware of the conflict, or ensure that explicitly setting prefer-online overrides the offline preference to force a network validation.
I have submitted a fix for this issue! The fix adds a warning message when both prefer-offline and prefer-online flags are detected, informing users that prefer-online will be ignored in favor of prefer-offline. PR: Jah-yee#1
Thanks so much for the quick response and for putting together this PR! Adding a warning will definitely save a lot of developers from the headache I just went through.
Looking at this from a structural perspective, I was wondering if it might make sense in the long run to merge these two mutually exclusive boolean flags into a single configuration key?
For example, replacing both prefer-offline and prefer-online with a single option like fetch-preference=online|offline (or something similar). This would completely eliminate the possibility of a conflicting state at the configuration level, making it structurally impossible for users to confuse the CLI.
Just a thought for future iterations! Thanks again for the quick fix.
I'd like to work on this. Planning to add a conflict check in the config validation layer and emit a warning when both prefer-offline and prefer-online are set. Will submit a PR
Activity
gmvp3 commentedon Mar 13, 2026
Thanks so much for the quick response and for putting together this PR! Adding a warning will definitely save a lot of developers from the headache I just went through.
Looking at this from a structural perspective, I was wondering if it might make sense in the long run to merge these two mutually exclusive boolean flags into a single configuration key?
For example, replacing both prefer-offline and prefer-online with a single option like fetch-preference=online|offline (or something similar). This would completely eliminate the possibility of a conflicting state at the configuration level, making it structurally impossible for users to confuse the CLI.
Just a thought for future iterations! Thanks again for the quick fix.
fix(config): warn when both prefer-offline and prefer-online are set
mvanhorn commentedon Mar 18, 2026
Implemented in #9129 - adds a config conflict warning when both prefer-offline and prefer-online are set.
fix(config): use exclusive definitions for prefer-offline/prefer-online
owlstronaut commentedon Mar 24, 2026
we created a new bug, so i'm reverting that and reopening -- #9133
yetanotheraryan commentedon Mar 29, 2026
I'd like to work on this. Planning to add a conflict check in the config validation layer and emit a warning when both prefer-offline and prefer-online are set. Will submit a PR
alialkhtri3-png commentedon Sep 1, 2026
npm install --prefer-online --prefer-offline=false