Skip to content

"Re-optimizing dependencies because vite config has changed" using vitest + vite-rolldown #870

@jhnns

Description

@jhnns

Related plugins

Describe the bug

First of all, I'm not sure where best to report the issue, but since the bug can be fixed with a quick fix in this repository (see below), I think that's the best place to start.

When I use the plugin in vitest and with vite-rolldown, I get the following warning in the console:

Both esbuild and oxc options were set. oxc options will be used and esbuild options will be ignored.
[vite] (client) Re-optimizing dependencies because vite config has changed
[vite] (client) ✨ optimized dependencies changed. reloading

[vitest] Vite unexpectedly reloaded a test. This may cause tests to fail, lead to flaky behaviour or duplicated test runs.
For a stable experience, please add mentioned dependencies to your config's `optimizeDeps.include` field manually.

The problem seems to be related with this change. If I revert

optimizeDeps: {
  rollupOptions: {
    transform: { jsx: { runtime: "automatic" } }
  }
}

to

optimizeDeps: {
  rollupOptions: { jsx: { mode: "automatic" } },
}

it goes away. Unfortunately I couldn't find any documentation about this option in vite-rolldown.

Reproduction

https://github.com/jhnns/vitest-rolldown-react-bug

Steps to reproduce

  1. npm i
  2. npm test

It will output the warning.

Note: Although the test do run in this example, this causes our test suite to fail in the first run when running vitest (in watch mode):

Error: Failed to import test file /path/to/our/test-setup/file.ts
Caused by: Error: Vitest failed to find the runner. This is a bug in Vitest. Please, open an issue with reproduction.

If I run the test a second time (pressing Enter) it will succeed.
This problem only exists with vite-rolldown, it won't happen with regular vite.

System Info

System:
  OS: macOS 15.6.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 106.03 MB / 32.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 22.14.0 - ~/.local/state/fnm_multishells/51238_1757933721456/bin/node
  Yarn: 1.22.22 - ~/.local/state/fnm_multishells/51238_1757933721456/bin/yarn
  npm: 10.9.2 - ~/.local/state/fnm_multishells/51238_1757933721456/bin/npm
  pnpm: 9.15.9 - ~/.local/state/fnm_multishells/51238_1757933721456/bin/pnpm
Browsers:
  Chrome: 140.0.7339.133
  Safari: 18.6
npmPackages:
  @vitejs/plugin-react: ^5.0.2 => 5.0.2 
  @vitejs/plugin-react-oxc: ^0.4.1 => 0.4.1 
  rolldown-vite:  7.1.10

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions