-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
vitest errors on cyclic imports #4143
Comments
Start a new pull request in StackBlitz Codeflow. |
There error is here,
https://github.com/amazon-ion/ion-js/blob/master/src/dom/Blob.ts#L9 Ion.js re-exports IonTypes from IonTypes.js
https://github.com/amazon-ion/ion-js/blob/master/src/Ion.ts#L134 Which defines a keys for IonType instances, like an enum.
https://github.com/amazon-ion/ion-js/blob/master/src/IonTypes.ts#L16 |
Okay, I have a minimal reproduction now with a few lines can be imported with node but fail in vitest.
The issue is related to stateDiagram-v2
[*] --> Ion.js
Ion.js --> IonTypes.js: export { IonTypes }
Ion.js --> dom/index.js: import * as dom
dom/index.js --> dom/Blob.js: export { Blob }
dom/Blob.js --> Ion.js: import { IonTypes }
|
Same problem here. Just run Versionvitest 0.34.4 |
Looks like this is a Vite SSR limitation. This code also fails there (Vitest reuses the same transforms): import { createServer } from 'vite';
const server = await createServer()
const { callFactory } = await server.ssrLoadModule('./src/module/utils.ts')
callFactory()
await server.close() |
Is there any workaround available? (besides refactoring the codebase) 😞 |
hey guys, any updates on this? |
There's an open issue on Vite for this: vitejs/vite#14048 |
Describe the bug
When importing certain modules with cyclical imports vitest will evaluate a file before it's imports are undefined, causing unexpected
TypeError: _ is undefined
errors. I was not able to reproduce this error in esbuild, vite, or nodejs.Reproduction
Unfortunately I haven't been able to create a minimal reproduction. The only example I have is importing ion-js. The vitest error is
I'm reporting this as a vitest error because I can't reproduce it in any other system.
vitest
https://stackblitz.com/edit/vitest-dev-vitest-cpxaqv?file=test%2Fbasic.test.ts
esbuild
node.js
This uses dist/commonjs/es6, not dist/es6/es6 like vitest and esbuild because ion-js doesn't build node compatible esm. I ran a codemod converting the package to true node esm (adds extensions and type:module) and got the same result.
vite
I tried to reproduce this in vite client and server side but never saw the error.
https://stackblitz.com/edit/vitejs-vite-mmhd5y?file=server.js
https://github.com/amazon-ion/ion-js/blob/master/src/dom/Blob.ts#L1
https://github.com/amazon-ion/ion-js/blob/master/src/Ion.ts#L134
https://github.com/amazon-ion/ion-js/blob/master/src/IonTypes.ts#L16
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: