Skip to content

npm monorepo: root vite override may not apply when a new member adds a package that depends on vite #3455

Open

Description

@naokihaba

Describe the bug

I created a monorepo using vp create vite:monorepo --package-manager npm. The root package.json defines an override like this:

"overrides": {
  "vite": "npm:@voidzero-dev/vite-plus-core@1.5.0"
}

When I added a package that depends on vite to a new, empty workspace member, npm didn't apply this override. Instead, it installed upstream vite@8.3.8 under node_modules/vitepress/node_modules/vite and wrote that to package-lock.json. Running vp install afterward didn't fix it either. I only got the override to work after deleting node_modules and package-lock.json and running a clean install.

Because npm didn't throw any errors and the build succeeded, it's very easy to miss that the package is actually running upstream Vite.

This seems like an npm issue. I tested a plain npm workspace with just the root override on npm 11.20.0 and 12.2.2, and ran into the exact same behavior. Still, I wanted to bring it up here since it impacts Vite+ monorepos using npm. From what I can tell, #1728 verified fresh installs across npm, yarn, and bun, but this scenario is a bit different because the package is added later with npm install <pkg>.

For context, I couldn't reproduce this when:

  • Adding vitepress to apps/website, which already depends on vite-plus
  • Testing a standalone project created with vp create vite:application --package-manager npm, which has a direct vite dependency at the root

Reproduction

https://github.com/naokihaba/npm-overrides-first-install-repro

Steps to reproduce

git clone https://github.com/naokihaba/npm-overrides-first-install-repro
cd npm-overrides-first-install-repro
./repro.sh

The script needs the global vp CLI. It creates the monorepo in a temporary directory and does these steps:

  1. Run vp create vite:monorepo --package-manager npm.
  2. Add an empty workspace member apps/docs, and run vp install.
  3. Run vp add -D vitepress@2.0.0-alpha.21 --filter docs. vitepress depends on vite@^8.3.4.
  4. Run vp install again with no changes.
  5. Remove node_modules and package-lock.json, and run vp install.

After steps 3, 4, and 5, the script prints the package that vite resolves to from vitepress:

3. vp add -D vitepress@2.0.0-alpha.21 --filter docs (first time vitepress enters the tree)
  vite -> vite@8.3.8
  path: node_modules/vitepress/node_modules/vite/package.json
  overrides applied: NO

4. vp install (again, no changes to package.json)
  vite -> vite@8.3.8
  path: node_modules/vitepress/node_modules/vite/package.json
  overrides applied: NO

5. Remove node_modules and package-lock.json, then vp install
  vite -> @voidzero-dev/vite-plus-core@1.5.0
  path: node_modules/vite/package.json
  overrides applied: yes

System Info

$ vp env current
Node.js:
  Version    26.13.1
  Source     engines.node
  Bin Path   ~/.vite-plus/js_runtime/node/26.13.1/bin/node
  Installed  true
  Mode       managed

Package Manager:
  Name       npm
  Version    12.2.2
  Source     devEngines.packageManager
  Bin Paths
    npm      ~/.vite-plus/package_manager/npm/12.2.2/npm/bin/npm
    npx      ~/.vite-plus/package_manager/npm/12.2.2/npm/bin/npx
  Installed  true
  Mode       managed

$ vp --version
vp v1.5.0

Local vite-plus:
  vite-plus  v1.5.0

Tools:
  vite             v8.3.5
  rolldown         v1.2.16
  vitest           v5.1.0
  oxfmt            v0.76.0
  oxlint           v1.91.0
  oxlint-tsgolint  v7.0.2005
  tsdown           v0.23.4

Environment:
  Package manager  npm v12.2.2
  Node.js          v26.13.1 (engines.node)


macOS 27.0, arm64

Used Package Manager

npm

Logs

Validations

Activity

  1. self-assigned this
    on Nov 14, 2026
  2. added theissue type on Nov 14, 2026
  3. voidzero-bot commented on Nov 14, 2026

    @voidzero-bot
    Contributor
    • Reproduced: No
    • Exploration: Already fixed on main
    • Unit Test: No — the failure is environmental/lockfile-level and would require an end-to-end vp create/vp add sequence; no focused test was added during triage.
    • Priority: P2: Has Workaround. This affects a specific npm-workspace workflow (adding a vite-dependent package to a new, empty member), and the reporter already documented a reliable workaround: removing node_modules and package-lock.json and running a clean install restores the override.

    On current main with npm 12.2.2, I could not reproduce the reported behavior. After creating an npm monorepo, adding an empty apps/docs member, and running vp add -D vitepress@2.0.0-alpha.21 --filter docs, the root vite override resolved to @voidzero-dev/vite-plus-core immediately, with no upstream vite nested under vitepress. Re-running vp install and performing a clean install both kept the override. The reporter noted the same symptom occurs in a plain npm workspace, which suggests the original failure was driven by an upstream npm lockfile quirk that is no longer triggered (or is masked) in the current Vite+/npm combination tested here.

    This issue appears to have already been fixed. Try upgrading to the latest Vite+ release (vp upgrade or reinstall the global vp CLI) and running a clean install in the affected monorepo. If the behavior still occurs after that, please include the output of vp --version, node -v, and npm -v from the affected project.

    Full Triage Report

    Triage Report: #3455

    Issue Summary

    In a Vite+ npm monorepo, the root overrides entry that redirects vite to a
    scoped replacement package may not be applied when a new, empty workspace member
    adds a package that depends on vite. The reporter observed that vitepress
    added to apps/docs resolved to upstream vite@8.3.8 under
    node_modules/vitepress/node_modules/vite, and only a clean install
    (rm -rf node_modules package-lock.json && npm install) corrected the tree.

    The reporter also verified the same behavior in a plain npm workspace without
    Vite+, suggesting this is an upstream npm issue.

    Environment Used

    Reproduction Path

    Started from the Vite+ checkout on the branch triagebot/fix-3455.

    Because the current main template overrides vite to
    @voidzero-dev/vite-plus-core@8.3.8000, an unpublished development version, the
    public registry would fail during install. To keep the reproduction focused on
    the override behavior rather than a missing-package error, all npm-using
    commands were run through the local registry helper so that
    @voidzero-dev/vite-plus-core@8.3.8000 resolved from the checkout packages.

    Commands executed:

    1. Create the monorepo:

      node "$VITE_PLUS_REPO/packages/tools/src/local-npm-registry.ts" --pack -- \
        vp create vite:monorepo --directory mono --package-manager npm \
        --no-interactive --no-agent --no-editor --no-hooks
      # cd mono
      # npm (devEngines): 12.2.2
      # root overrides: {"vite":"npm:@voidzero-dev/vite-plus-core@8.3.8000"}
      # exit: 0
    2. Add an empty workspace member apps/docs and install:

      mkdir -p apps/docs
      echo '{"name":"docs","private":true}' > apps/docs/package.json
      node "$VITE_PLUS_REPO/packages/tools/src/local-npm-registry.ts" --pack -- vp install
      # exit: 0
    3. Add vitepress@2.0.0-alpha.21 to apps/docs:

      node "$VITE_PLUS_REPO/packages/tools/src/local-npm-registry.ts" --pack -- \
        vp add -D vitepress@2.0.0-alpha.21 --filter docs
      # exit: 0
    4. Run check.ts from the reproduction repository:

      node /tmp/vite-plus-triage/gh-3455/repro/check.ts "$mono" apps/docs
      # vite -> @voidzero-dev/vite-plus-core@8.3.8000
      # path: node_modules/vite/package.json
      # overrides applied: yes
    5. Run vp install again with no changes:

      node "$VITE_PLUS_REPO/packages/tools/src/local-npm-registry.ts" --pack -- vp install
      # exit: 0
      # check.ts output: overrides applied: yes
    6. Clean install as a control:

      rm -rf node_modules apps/*/node_modules packages/*/node_modules package-lock.json
      node "$VITE_PLUS_REPO/packages/tools/src/local-npm-registry.ts" --pack -- vp install
      # exit: 0
      # check.ts output: overrides applied: yes

    Result

    The reported behavior did not reproduce on the current checkout:

    • After adding vitepress to the new empty member, the override was applied
      immediately.
    • No nested node_modules/vite appeared under vitepress.
    • Re-running vp install without changes kept the override.
    • A clean install also applied the override.
    • package-lock.json recorded the override target
      ("vite": "npm:@voidzero-dev/vite-plus-core@8.3.8000").

    Early-Exit Considerations

    None of the skip reasons applied:

    • The report is a reproducible bug report, not a feature/support request.
    • A usable reproduction repository and steps were provided.
    • The required package-manager and runtime versions can be installed on the
      runner (vp downloaded npm 12.2.2 on demand).
    • The issue is not host-specific; it was tested on Linux x64.
    • No maintainer override was present.

    Observations

    • The reproduction repository, as written, fails earlier in step 2 on current
      main because the template pins @voidzero-dev/vite-plus-core@8.3.8000,
      which is not published. The local registry wrapper was required to keep the
      test focused on override application rather than a missing-package failure.
    • Since the reporter noted the same behavior occurs with plain npm workspaces,
      the issue may be an upstream npm formatting/lockfile bug that does not
      trigger on every environment or npm version. Differences that could matter
      include platform (macOS vs Linux) or subtle npm patch-level behavior that
      has since changed.
    • On current main, Vite+ monorepos created with npm do not appear to
      exhibit the reported failure.

    Triage Conclusion

    • Status: Not reproduced on current main.
    • Recommended action: The issue may already be resolved in current Vite+
      or may depend on a specific npm/platform state. A maintainer could ask the
      reporter to re-test with the latest Vite+ and npm, or to confirm whether the
      behavior still reproduces in a plain npm workspace under the same conditions.

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  4. naokihaba commented on Nov 14, 2026

    @naokihaba
    CollaboratorAuthor

    The cause is npm/cli#4834. When a workspace member adds a dependency and a package-lock.json already exists, npm does not apply the root overrides to that dependency. This must be fixed in npm.

    Vite+ will not add a workaround. A workaround would have to change how npm writes the lockfile or installs packages, and the impact is small: vitepress build still works with upstream Vite.

    Until npm fixes the bug, delete package-lock.json and node_modules, then run vp install again. A fresh install applies the override.

    I will keep this issue open to track npm/cli#4834.

  5. voidzero-bot commented on Nov 14, 2026

    @voidzero-bot
    Contributor

    Automated triage could not be completed: the triage report (report.md) is missing or could not be read. Please inspect the triage run artifacts and logs for the reproduction, diagnosis, and verification results.

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

Metadata

Metadata

Assignees

Type

Fields

Priority

None yet

Effort

None yet

Target date

None yet

Start date

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions