Skip to content

Keep ecij's modules out of Vitest's file system module cache - #122

Merged
nstepien merged 5 commits into
mainfrom
vitest-fs-module-cache
Nov 4, 2026
Merged

nstepien merged 5 commits into
mainfrom
vitest-fs-module-cache

Conversation

@nstepien

@nstepien nstepien commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Vitest 5 turns on fsModuleCache by default. It stores transformed modules on disk and reuses them in later runs without calling transform, which is where ecij registers the stylesheet of each module. On the second run, a module that uses css imports a stylesheet that nothing registered, and its tests fail:

Cannot find module '/card.ts.878ec5b2.css' imported from …/card.ts

react-data-grid had to turn fsModuleCache off because of this. Vitest 5.1.0 fails the same way, as the cache works as documented: it keys a module on its own content, ID, and environment config, and plugins whose output depends on more should opt out with a cache key generator. ecij's output depends on more: the stylesheets live in the plugin's memory, and the CSS can interpolate values imported from other modules.

  • configureVitest defines a cache key generator that keeps every module referencing ecij out of the cache, like the code filter of transform. Other modules stay cached. It doesn't apply include and exclude, because their glob strings would need a matcher the plugin doesn't have, so an excluded module that mentions ecij isn't cached either.
  • The hook is typed with Vite's Plugin type, which vitest/config extends with configureVitest once tsconfig.src.json lists it in types. dist/index.d.ts references neither Vite nor Vitest.
  • vitest is an optional peer dependency (^5.0.0), as Vitest 4.1 has no defineCacheKeyGenerator. npm now rejects ecij in a Vitest 4.1 project (ERESOLVE), where Vitest would otherwise fail at startup with TypeError: defineCacheKeyGenerator is not a function. The README says ecij requires Vitest 5 or later. The Vite Plugin Registry does not track Vitest, so the plugin card doesn't change.
  • A new test runs the tests of a copy of the edits fixtures twice, each time with a new Vitest instance and plugin, like a new process. Without the hook, the second run fails with the error above.
  • AGENTS.md says why the hook and the peer dependency exist.

In a clone of react-data-grid's main with fsModuleCache: false removed and this branch packed, vpr ci passes, lib/ is identical to the build with the published 0.6.0, and vp test ssr.test passes twice in a row. With the published 0.6.0, its second run fails with Cannot find module '/src/utils/renderMeasuringCells.tsx.3c530dba.css'.

🤖 Generated with Claude Code

Vitest 5 reuses cached transforms across runs without calling transform,
which registers the stylesheets, so a rerun failed to resolve them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

nstepien and others added 4 commits November 3, 2026 23:58
Drop the fallback to Vitest 4.1's experimental_defineCacheKeyGenerator.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
configureVitest calls defineCacheKeyGenerator, which Vitest 4.1 lacks, so
package managers now reject ecij there instead of Vitest failing at startup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adding vitest/config to the types of tsconfig.src.json loads its
augmentation of Vite's Plugin interface, so the plugin picks both of its
Vite hooks from that one type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The helper no longer assigns the disposer to the Vitest instance.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nstepien
nstepien marked this pull request as ready for review November 4, 2026 00:51
@nstepien
nstepien merged commit 7d1a2df into main Nov 4, 2026
12 checks passed
@nstepien
nstepien deleted the vitest-fs-module-cache branch November 4, 2026 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant