Skip to content

vp env shouldn't intercept npm i -g #540

Closed

Description

@hyfdev

Some notes:

  • binaries installed by npm i -g will disappear is an already knonw behavior of fnm and nvm. This is a already a solid mental model for node users. I don't see a solid reason to break this mental model. How to install global npm tools that are available across all node versions Schniz/fnm#109 also introduce.
  • Volta introduces different behavior with an explicitly different command volta install instead of npm i -g.
    • Notice Votal also intercepts npm i -g. For Volta, it's also the same between volta install and npm i -g
  Comparison Table
  ┌───────┬───────────────────────────────────┬──────────────────────────────────────────────────────────┐
  │ Tool  │         Default Behavior          │                   Built-in Workaround                    │
  ├───────┼───────────────────────────────────┼──────────────────────────────────────────────────────────┤
  │ fnm   │ Isolated per-version              │ None (users complain)                                    │
  ├───────┼───────────────────────────────────┼──────────────────────────────────────────────────────────┤
  │ nvm   │ Isolated per-version              │ nvm reinstall-packages to copy from another version      │
  ├───────┼───────────────────────────────────┼──────────────────────────────────────────────────────────┤
  │ mise  │ Isolated per-version              │ .default-npm-packages auto-install, npm backend          │
  ├───────┼───────────────────────────────────┼──────────────────────────────────────────────────────────┤
  │ Volta │ Isolated + pinned to Node version │ Explicit design - volta install with clear communication │
  └───────┴───────────────────────────────────┴──────────────────────────────────────────────────────────┘

My proposal: Do not make npm i -g special

Reasons to Distinguish vp env install from npm i -g

1. Principle of Least Surprise

npm i -g has had the same behavior for 15+ years. Every Node developer knows:

  • Global packages go to the current Node version's directory
  • Switching Node versions means different global packages

Intercepting and changing this behavior silently violates user expectations. Even Volta, which does intercept, prints note: using Volta to install Yarn — acknowledging it's doing something unexpected.

2. Explicit is Better Than Implicit

  • vp env install explicitly says "I want vite-plus to manage this"
  • npm i -g should mean "I'm using npm directly"

Users who want isolation should ask for it. Users who want standard npm behavior shouldn't have to learn why their mental model is broken.

3. Migration Path from fnm/nvm

fnm and nvm users have muscle memory: npm i -g installs to current version, packages disappear when switching. This is annoying but understood.

If vite-plus intercepts npm i -g and isolates everything, these users face:

  • Unexpected behavior change
  • Confusion about where packages actually live
  • No way to get the "old" behavior without env vars

4. Debugging and Transparency

When npm i -g does what npm normally does:

  • Users can reason about the system
  • npm list -g shows what's installed
  • Standard npm troubleshooting applies

When intercepted:

  • Users don't know what's actually happening
  • npm list -g may show different results than expected
  • Adds a layer of magic that obscures problems

5. Two Distinct Use Cases Exist

Use case A: "I want typescript globally for this Node version"
→ npm i -g typescript (traditional, per-version)

Use case B: "I want typescript to always work regardless of Node version"
→ vp env install typescript (isolated, pinned)

These are different intents. One command shouldn't try to serve both.

6. Volta's Quirks Are a Warning

Volta intercepts npm i -g, but:

  • Updates require volta install (confusing)
  • --dry-run flag is ignored (bug from interception complexity)
  • pnpm global installs aren't intercepted (inconsistent)

Interception adds complexity and edge cases. Keeping commands separate avoids this.

7. Composability with Other Tools

Some users may want vite-plus only for Node version management, while using other tools (or raw npm) for package management. Interception forces an all-or-nothing approach.


Summary: Let npm i -g be npm i -g. Let vp env install be the explicitly better alternative. Users who want isolation will find it; users who don't won't be surprised.

Originally posted by @hyf0 in #528

Activity

  1. linear commented on Feb 4, 2026

    @linear
  2. changed the title [-]`vite env` shouldn't intercept `npm i -g`[/-] [+]`vp env` shouldn't intercept `npm i -g`[/+] on Feb 4, 2026
  3. hyfdev commented on Feb 5, 2026

    @hyfdev
    ContributorAuthor

    New version follows this behavior.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions