-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Description
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 indynamicImportVarsOptions - These default options are eventually merged with user-provided options using
vite'sdeepCloneimplementation. The regex literal is cloned via the nativestructuredClone(I don't thinkstructuredCloneis being polyfilled, but happy to be proven wrong). - This cloned config eventually makes its way to
@rollup/plugin-dynamic-import-vars. This plugin calls thiscreateFilterfunction which contains aninstanceof RegExpcheck. - The
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 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 [email protected]:askoufis/vite-node-issue.git
cd vite-node-issue
pnpm install
pnpm testTest 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.10Used Package Manager
pnpm
Logs
No response
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.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- 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.