Skip to content

Vite SSR doesn't overwrite * re-export by named export #19525

@hi-ogawa

Description

@hi-ogawa

Describe the bug

Example code

  • dep.js
export const a = "dep-a"
export const b = "dep-b"
export const c = "dep-c"
  • main.js
export const a = "main-a"
export * from "./dep.js"
export const c = "main-c"

expected

❯ node -e 'import("./src/main.js").then(console.log)'
[Module: null prototype] { a: 'main-a', c: 'main-c', b: 'dep-b' }

(Also rollup output on repl)

actual

# get "dep-a" instead of "main-a"
❯ node repro.js
{"a":"dep-a","b":"dep-b","c":"main-c"}

Side note: Current Vite SSR works if export const comes after export *. But, probably export hoisting PR #18983 currently breaks this pattern all the time. I think technically this is solvable if we gather local named export names first and then pass and exclude them from exportAll runtime function:

[ssrExportAllKey]: (obj: any) => exportAll(exports, obj),

Reproduction

https://stackblitz.com/edit/vitejs-vite-kkt7njfs?file=src%2Fmain.js

Steps to reproduce

  • Open stackblitz
  • run node repro.js
  • run node -e 'import("./src/main.js").then(console.log)'

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: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^6.2.0 => 6.2.0

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: ssrp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions