feat: add toggable injectCjsGlobals option#10709
Merged
Merged
Conversation
✅ Deploy Preview for vitest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
hi-ogawa
reviewed
Jul 7, 2026
…ve fetch module type
Member
Author
|
Important to sync with #10708 (or the other way around) because they touch the same mechanism |
hi-ogawa
approved these changes
Jul 8, 2026
sheremet-va
added a commit
that referenced
this pull request
Jul 8, 2026
The `fetchWarmModules` fast path serves inline modules to fresh workers without the `moduleType` tag the direct-fetch path attaches (#10709). With `injectCjsGlobals: false` the evaluator injects the CommonJS scope only into modules tagged `moduleType: 'cjs'`, so a CommonJS dependency read back from the snapshot evaluated without `require`/`module`/ `__dirname` and threw "require is not defined" — the first file worked (direct fetch) while every later file served from the snapshot failed. Recompute the tag in `fetchWarmModules` with the same `detectModuleType` the direct-fetch path uses, gated on `injectCjsGlobals === false` so the default path pays nothing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds
injectCjsGlobalsfor projects that keep using the module runner to run tests, but need a more fair environment (ESM files do not have access to CJS globals).cjs(we use Node.js algorithm to check it)strictModuleTypeoption to disable CJS-ESM interop #10292Thanks Fable
I am hoping to disable this by default in Vitest 6