-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Labels
feat: ssrp2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)
Description
Describe the bug
Related vitest-dev/vitest#4143 (comment)
- main.js
export * from './dep1.js';
import './dep2.js';- dep1.js
console.log('dep1');
export {};- dep2.js
console.log('dep2');
export {};On Node:
❯ node src/main.js
dep1
dep2On Vite module runner:
❯ node repro.js
dep2
dep1SSR transform doesn't hoist __vite_ssr_import__ for re-export. I think hoisting should give more intuitive execution order. The issue is recognized by a following test and probably already discussed in #14468 and #14441.
vite/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Lines 1247 to 1270 in 172cbed
| test('import and export ordering', async () => { | |
| // Given all imported modules logs `mod ${mod}` on execution, | |
| // and `foo` is `bar`, the logging order should be: | |
| // "mod a", "mod foo", "mod b", "bar1", "bar2" | |
| expect( | |
| await ssrTransformSimpleCode(` | |
| console.log(foo + 1) | |
| export * from './a' | |
| import { foo } from './foo' | |
| export * from './b' | |
| console.log(foo + 2) | |
| `), | |
| ).toMatchInlineSnapshot(` | |
| "const __vite_ssr_import_0__ = await __vite_ssr_import__("./foo", {"importedNames":["foo"]}); | |
| console.log(__vite_ssr_import_0__.foo + 1); | |
| const __vite_ssr_import_1__ = await __vite_ssr_import__("./a");__vite_ssr_exportAll__(__vite_ssr_import_1__); | |
| ; | |
| const __vite_ssr_import_2__ = await __vite_ssr_import__("./b");__vite_ssr_exportAll__(__vite_ssr_import_2__); | |
| ; | |
| console.log(__vite_ssr_import_0__.foo + 2) | |
| " | |
| `) | |
| }) |
The situation might have changed after #18983, so I'll check what happens if we hoist these now.
Reproduction
https://stackblitz.com/edit/vitejs-vite-ffvhx4qg?file=src%2Fmain.js
Steps to reproduce
Open stackblitz
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: 20.19.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
vite: ^6.2.2 => 6.2.6Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: ssrp2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)