-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
fix(ssr): hoist export to handle cyclic import better #18983
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
Changes from 6 commits
5f8c6fd
b537976
3cc86da
ed79e4d
95f47eb
2245aaa
a8c1d12
c2f7d75
96f123a
d5b2333
d252b5c
7904808
45e74ac
83a7a1f
af7de84
b0b75eb
958467a
19f7533
059d132
677949c
a844104
94a2d1f
7d75d1f
1d5110e
7e7b660
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Cyclic import example based on https://github.com/vitejs/vite/issues/14048#issuecomment-2354774156 | ||
|
|
||
| ```mermaid | ||
| flowchart TD | ||
| B(dep1.js) -->|dep1| A(index.js) | ||
| A -->|dep1| C(dep2.js) | ||
| C -->|dep2| A | ||
| A -->|dep1, dep2| entry.js | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "type": "module" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const dep1 = { ok: true }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import { dep1 } from "./index.js" | ||
| export const dep2 = { ok: dep1.ok } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { dep1 } from './dep1.js' | ||
| export { dep1 } | ||
|
|
||
| import { dep2 } from './dep2.js' | ||
| export { dep2 } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const dep1 = { ok: true }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import { dep1 } from "./index.js" | ||
| export const dep2 = { ok: dep1.ok } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { dep1 } from './dep1.js' | ||
| export { dep2 } from "./dep2.js" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const dep1 = { ok: true }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import { dep1 } from "./index.js" | ||
| export const dep2 = { ok: dep1.ok } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { dep1 } from './dep1.js' | ||
| import { dep2 } from './dep2.js' | ||
| export { dep1 } | ||
| export { dep2 } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const dep1 = { ok: true }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import { dep1 } from "./index.js" | ||
| export const dep2 = { ok: dep1.ok } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './dep1.js' | ||
| export * from './dep2.js' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const dep1 = { ok: true }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import { dep1 } from "./index.js" | ||
| export const dep2 = { ok: dep1.ok } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { dep2 } from './dep2.js' | ||
| export { dep2 } | ||
|
|
||
| import { dep1 } from './dep1.js' | ||
| export { dep1 } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,11 @@ export default defineConfig({ | |
| './playground-temp/**/*.*', | ||
| ], | ||
| testTimeout: 20000, | ||
| isolate: false, | ||
| // isolate: false, | ||
| // TODO: | ||
| // importing non entry file can be broken due to cyclic import e.g. | ||
| // pnpm exec tsx packages/vite/src/node/server/index.ts | ||
| setupFiles: ['./packages/vite/src/node/index.ts'], | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interestingly, export hoisting can make cyclic import handling stricter as seen by: $ pnpm test-unit packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts
FAIL packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts [ packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts ]
ReferenceError: Cannot access 'serverConfigDefaults' before initialization
❯ Module.get [as serverConfigDefaults] packages/vite/src/node/server/index.ts:4:116but this case might be legitimate since this is the same error as $ pnpm exec tsx packages/vite/src/node/server/index.ts
/home/hiroshi/code/others/vite/packages/vite/src/node/config.ts:648
server: serverConfigDefaults,
^
ReferenceError: Cannot access 'serverConfigDefaults' before initializationI'd imagine previously these were Just temporarily, I added this silly |
||
| }, | ||
| esbuild: { | ||
| target: 'node18', | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out the error now became same as
playground/hmrbut module runner doesn't auto-reload, so the existing test failed.I adjust this test case for now to make it pass.