Describe the bug
I'm a maintainer of Vanilla Extract. We use vite-node to execute files for the purpose of generating classnames and eventually CSS. With the release of vitest v3, I was keen to upgrade both vite-node to v3 and our vite peer dep to include v6. However, while attempting to update I noticed that some of our tests began failing.
The failing tests are related to our vite-node-based compiler. We test the compiler in both vitest and jest, mainly to be thorough, and our tests are only failing in jest. vitest tests are passing.
After some debugging, my understanding of what's causing the error in the reproduction is as follows:
- Vite creates some default build options, specifically this
/node_modules/ regex literal specified in dynamicImportVarsOptions
- These default options are eventually merged with user-provided options using
vite's deepClone implementation. The regex literal is cloned via the native structuredClone (I don't think structuredClone is being polyfilled, but happy to be proven wrong).
- This cloned config eventually makes its way to
@rollup/plugin-dynamic-import-vars. This plugin calls this createFilter function which contains an instanceof RegExp check.
- The
instanceof RegExp check fails against the cloned /node_modules/ regex literal, resulting in an incorrect code branch being taken, eventually resulting in this isAbsolute call being passed a regex literal, causing the error.
As mentioned below in the reproduction, this error does not occur on vite 5.x. At this point I'm unsure if the issue is prototype pollution, or maybe some kind of multiple realm-related issue.
Another theory I had is that this is somehow related to the new environments feature because the code that accesses dynamicImportVarsOptions and calls createFilter was changed as part of that feature implementation, but that's really just speculation on my end.
Workaround
Passing in my own /node_modules/ regex literal when calling createServer results in the test passing. E.g.:
const server = await createServer({
optimizeDeps: {
noDiscovery: true,
include: undefined,
},
build: {
dynamicImportVarsOptions: {
exclude: [/node_modules/],
},
},
});
Impact
AFAIK most (if not all) consumers of Vanilla Extract would not be testing this compiler directly, nor would they likely test any bundler integrations that depend on the compiler, so there's likely no impact to consumers.
I appreciate that this is a bit of a niche/strange use case (testing vite-node in jest), so I'd completely understand if the ultimate decision is that this issue will not be fixed.
Reproduction
https://github.com/askoufis/vite-node-issue
Steps to reproduce
git clone git@github.com:askoufis/vite-node-issue.git
cd vite-node-issue
pnpm install
pnpm test
Test should fail with the error:
TypeError: The "path" argument must be of type string. Received an instance of RegExp
Downgrading vite to a 5.x version (e.g. 5.4.13) makes the test pass. Downgrading vite-node has no effect.
System Info
System:
OS: macOS 15.1.1
CPU: (10) arm64 Apple M1 Pro
Memory: 2.95 GB / 32.00 GB
Shell: 3.7.1 - /opt/homebrew/bin/fish
Binaries:
Node: 20.9.0 - ~/.local/share/mise/installs/node/20.9.0/bin/node
npm: 10.1.0 - ~/.local/share/mise/installs/node/20.9.0/bin/npm
pnpm: 9.15.4 - ~/.local/share/mise/installs/node/20.9.0/bin/pnpm
bun: 1.1.43 - /opt/homebrew/bin/bun
Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
Browsers:
Safari: 18.1.1
npmPackages:
vite: ^6.0.10 => 6.0.10
Used Package Manager
pnpm
Logs
No response
Validations
Describe the bug
I'm a maintainer of Vanilla Extract. We use
vite-nodeto execute files for the purpose of generating classnames and eventually CSS. With the release ofvitestv3, I was keen to upgrade bothvite-nodeto v3 and ourvitepeer dep to include v6. However, while attempting to update I noticed that some of our tests began failing.The failing tests are related to our
vite-node-based compiler. We test the compiler in bothvitestandjest, mainly to be thorough, and our tests are only failing injest.vitesttests are passing.After some debugging, my understanding of what's causing the error in the reproduction is as follows:
/node_modules/regex literal specified indynamicImportVarsOptionsvite'sdeepCloneimplementation. The regex literal is cloned via the nativestructuredClone(I don't thinkstructuredCloneis being polyfilled, but happy to be proven wrong).@rollup/plugin-dynamic-import-vars. This plugin calls thiscreateFilterfunction which contains aninstanceof RegExpcheck.instanceof RegExpcheck fails against the cloned/node_modules/regex literal, resulting in an incorrect code branch being taken, eventually resulting in thisisAbsolutecall being passed a regex literal, causing the error.As mentioned below in the reproduction, this error does not occur on
vite5.x. At this point I'm unsure if the issue is prototype pollution, or maybe some kind of multiple realm-related issue.Another theory I had is that this is somehow related to the new environments feature because the code that accesses
dynamicImportVarsOptionsand callscreateFilterwas changed as part of that feature implementation, but that's really just speculation on my end.Workaround
Passing in my own
/node_modules/regex literal when callingcreateServerresults in the test passing. E.g.:Impact
AFAIK most (if not all) consumers of Vanilla Extract would not be testing this compiler directly, nor would they likely test any bundler integrations that depend on the compiler, so there's likely no impact to consumers.
I appreciate that this is a bit of a niche/strange use case (testing
vite-nodeinjest), so I'd completely understand if the ultimate decision is that this issue will not be fixed.Reproduction
https://github.com/askoufis/vite-node-issue
Steps to reproduce
Test should fail with the error:
Downgrading vite to a
5.xversion (e.g.5.4.13) makes the test pass. Downgradingvite-nodehas no effect.System Info
System: OS: macOS 15.1.1 CPU: (10) arm64 Apple M1 Pro Memory: 2.95 GB / 32.00 GB Shell: 3.7.1 - /opt/homebrew/bin/fish Binaries: Node: 20.9.0 - ~/.local/share/mise/installs/node/20.9.0/bin/node npm: 10.1.0 - ~/.local/share/mise/installs/node/20.9.0/bin/npm pnpm: 9.15.4 - ~/.local/share/mise/installs/node/20.9.0/bin/pnpm bun: 1.1.43 - /opt/homebrew/bin/bun Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman Browsers: Safari: 18.1.1 npmPackages: vite: ^6.0.10 => 6.0.10Used Package Manager
pnpm
Logs
No response
Validations