Skip to content
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

vite errors on cyclic imports #14433

Closed
7 tasks done
everett1992 opened this issue Sep 21, 2023 · 3 comments · Fixed by #14441
Closed
7 tasks done

vite errors on cyclic imports #14433

everett1992 opened this issue Sep 21, 2023 · 3 comments · Fixed by #14441
Labels
feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@everett1992
Copy link

everett1992 commented Sep 21, 2023

Describe the bug

I originally reported this in vitest-dev/vitest#4143 but now I can reproduce in vite.

When importing certain modules with cyclical imports vitest will evaluate a file before it's imports are undefined, causing unexpected TypeError: _ is undefined errors. The module can be imported as native ESM in node and works in esbuild.

Reproduction

https://stackblitz.com/edit/vitejs-vite-bouzoh?file=server.js

Steps to reproduce

I found this bug when using https://github.com/amazon-ion/ion-js. Here's a simplified version that reproduces the issue

ion-js
├── dom
│   ├── Blob.js
│   └── index.js
├── Ion.js
└── IonTypes.js
// ion-js/Ion.js
export { IonTypes } from "./IonTypes.js";
import * as dom from "./dom/index.js";
export { dom };
// ion-js/IonTypes.js
export const IonTypes = {
    BLOB: "Blob",
};
// ion-js/dom/index.js
export { Blob } from "./Blob.js";
// ion-js/dom/Blob.js
import { IonTypes } from "../Ion.js";
export const Blob =  IonTypes.BLOB

The issue is related to import * as dom from "./dom/index.js"; in Ion.js. If that is replaced with export * as dom from './dom/index.js' or import { Blob } from './dom/Blob.js' the issue doesn't reproduce.

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 }

Loading

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.20.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
    pnpm: 8.6.10 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^4.4.9 => 4.4.9

Used Package Manager

npm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented Sep 21, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@rtsao
Copy link
Contributor

rtsao commented Sep 21, 2023

I also reported this in #14010

@JonasDoesThings
Copy link

Is there any workaround available? (besides refactoring the codebase) 😞

@bluwy bluwy added p3-minor-bug An edge case that only affects very specific usage (priority) feat: ssr and removed pending triage labels Jan 8, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants