Skip to content

vm pools run Vite's dependency optimizer over index.html; an unbundlable dependency aborts the run (exit 1) though all tests pass #11329

Description

@iKyi

Describe the bug

When the pool is vmThreads (or vmForks), Vite's dependency optimizer runs over the project's index.html import graph and pre-bundles what it finds. If a dependency reached from index.html cannot be bundled, the run ends with an unhandled rejection and exit code 1, even when every test passes and no test imports that dependency. With pool: 'threads' the same project exits 0.

Our case: an app whose index.html entry reaches react-native (Flow source) via react-native-web. Every test passed under threads; under vmThreads the run aborted with [PARSE_ERROR] Flow is not supported from react-native/Libraries/Utilities/codegenNativeComponent.js.

From reading dist/chunks/cli-api-*.js: a vm pool adds the __vitest_vm__ Vite environment (consumer: "client"), and the configEnvironment hook returns early for it (if (name === "__vitest_vm__" || name === "__vitest__") return;). So it never gets the resolveOptimizerConfig(...) override the other environments get, and it keeps Vite's client default: discover dependencies from every index.html. Since vm tests load modules through native import, it looks like the optimizer has no work to do in that environment at all.

Setting optimizeDeps.noDiscovery at the top level does not help. Setting it on the environment does:

environments: { __vitest_vm__: { optimizeDeps: { noDiscovery: true } } },

That is our current workaround, but it depends on an internal environment name.

Reproduction

https://github.com/iKyi/vitest-vm-repros/tree/main/optimizer

index.html loads main.js, which imports flowdep (a local package with Flow annotations, installed as a real package via .npmrc install-links=true). The only test is expect(1).toBe(1).

npm install
npx vitest run                  # config pool vmThreads: all tests pass, exit 1
npx vitest run --pool=threads   # exit 0
Unhandled Rejection
Error: Error during dependency optimization:
Build failed with 1 error:
[PARSE_ERROR] Flow is not supported
variant exit
pool vmThreads 1
pool threads 0
vmThreads + top-level optimizeDeps: { noDiscovery: true } 1
vmThreads + environments.__vitest_vm__.optimizeDeps.noDiscovery 0
vmThreads, index.html removed 0

System Info

System:
  OS: Linux 7.0 Ubuntu 26.04.1 LTS
  CPU: (32) x64 AMD RYZEN AI MAX+ 395 w/ Radeon 8060S
Binaries:
  Node: 22.22.3
  npm: 10.9.8
npmPackages:
  happy-dom: 20.14.5
  vitest: 5.0.1
  vite: 8.3.0
  rolldown: 1.2.9

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
  • The provided reproduction is a minimal reproducible example of the bug.

Activity

  1. added
    p3-minor-bugAn edge case that only affects very specific usage (priority)
    on Sep 28, 2026
  2. added theissue type on Sep 28, 2026
  3. added a commit that references this issue on Sep 29, 2026
    caf2887
  4. added a commit that references this issue on Oct 7, 2026
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

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions