instanceof RegExp
check fails when testing vite-node
runner in Jest with Vite 6.x
#19245
Closed
7 tasks done
Labels
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 ofvitest
v3, I was keen to upgrade bothvite-node
to v3 and ourvite
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 bothvitest
andjest
, mainly to be thorough, and our tests are only failing injest
.vitest
tests are passing.After some debugging, my understanding of what's causing the error in the reproduction is as follows:
/node_modules/
regex literal specified indynamicImportVarsOptions
vite
'sdeepClone
implementation. The regex literal is cloned via the nativestructuredClone
(I don't thinkstructuredClone
is being polyfilled, but happy to be proven wrong).@rollup/plugin-dynamic-import-vars
. This plugin calls thiscreateFilter
function which contains aninstanceof RegExp
check.instanceof RegExp
check fails against the cloned/node_modules/
regex literal, resulting in an incorrect code branch being taken, eventually resulting in thisisAbsolute
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 callscreateFilter
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 callingcreateServer
results 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-node
injest
), 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.x
version (e.g.5.4.13
) makes the test pass. Downgradingvite-node
has no effect.System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: