Skip to content

[BUG] Silent conflict when both prefer-offline=true and prefer-online=true are set, causing npm view to return stale cached data #9113

Open

Description

@gmvp3

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

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.

Steps To Reproduce

No response

Environment

No response

Activity

  1. added
    Bug
    Needs Triage
    on Mar 13, 2026
  2. gmvp3 commented on Mar 13, 2026

    @gmvp3
    Author

    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.

  3. added a commit that references this issue on Mar 18, 2026
    ca7a4c2
  4. mvanhorn commented on Mar 18, 2026

    @mvanhorn
    Contributor

    Implemented in #9129 - adds a config conflict warning when both prefer-offline and prefer-online are set.

  5. added a commit that references this issue on Mar 18, 2026
    06fb29e
  6. owlstronaut commented on Mar 24, 2026

    @owlstronaut

    we created a new bug, so i'm reverting that and reopening -- #9133

  7. yetanotheraryan commented on Mar 29, 2026

    @yetanotheraryan
    Contributor

    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

  8. alialkhtri3-png commented on Sep 1, 2026

    @alialkhtri3-png

    npm install --prefer-online --prefer-offline=false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds Triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions