-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module transform causes errors in tests #16452
Labels
Comments
Update on this: It works if I change the build process of the log package from using Babel and Terser to using ESBuild. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
I originally opened this issue in the Vitest repo but was told to come here.
I have an external package called
@hex-insights/log
, when I import this package and try to instantiate any class in my app using Vitest I encounter the error (works fine with just Vite for dev server or build):Here is the source from the log package:
and in my test I have:
Here is my
vitest.config.ts
file:I've done some digging and found the issue has to do with the way vitest transforms modules.
Here is the original package from
node_modules
:And here is the version that vitest uses (received from the output of
test.server.debug.dumpModules: true
:That's a lot of minified code, so here are the important parts:
I'm dealing with the
ASmallClass
class, which is defined astt
and looks like this originally:but from the vitest transformed version looks like this:
Where
d
(the thrower of the error) is:Now, at the top of the original file I have:
So the issue is that
t
in thed
call is getting replaced with the importedt
, which then causesd
to the throw the error. My guess is that vitest is incorrectly replacing allt
variables with__vite_ssr_import_0__.getObjectKeys
even though in this caset
should clearly be the locally definedt
function.How can I fix this issue? Is it possible to disable the module transform? Is it possible to have the module transform work correctly?
Reproduction
It's hard to provide a reproduction because these packages are private and owned by my company.
Steps to reproduce
No response
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: