Skip to content

Module runner: export * from a module still evaluating in a cycle never gets its later exports (undefined where Node has the value) #24183

Description

@Sheraff

Written with the help of an AI coding agent (Claude); reproduced locally.

Describe the bug

When b.js does export * from './a.js' while a.js is still evaluating (an import cycle), b.js never gets the exports a.js gains afterwards through its own export *. Reading b.js's export after the whole graph has finished gives undefined; native ESM gives the value. Swapping the two imports in entry.js makes it work.

Reproduction

// entry.js
import { value as fromA } from './a.js'
import { value as fromB } from './b.js'

export const result = { fromA, fromB }
// a.js
export * from './b.js'
export * from './leaf.js'
// b.js
export * from './a.js'
// leaf.js
export const value = 42
// repro.mjs (with "type": "module" in package.json)
import { createServer } from 'vite'

// Native ESM
const native = await import('./entry.js')
console.log('node:', native.result)

// Vite SSR (module runner)
const server = await createServer({ configFile: false, appType: 'custom' })
const viaVite = await server.ssrLoadModule('/entry.js')
console.log('vite:', viaVite.result)
await server.close()
npm install vite
node repro.mjs

Actual (8.3.8, 8.4.0-beta.1, 7.3.8; same with server.environments.ssr.runner.import):

node: { fromA: 42, fromB: 42 }
vite: { fromA: 42, fromB: undefined }

Expected: vite: { fromA: 42, fromB: 42 }. Star exports are resolved at link time, so b.js's value is leaf.js's binding whatever the evaluation order, and entry.js runs after all of them. After the load, Object.keys of b.js's namespace is [] in Vite and ['value'] in Node.

Likely spot: exportAll in module-runner/runner.ts copies the source's keys once, when the export * runs, and a.js has no keys yet at that point.

Related: #22491 (same family, but there the missing export is only missing during the cycle; PR #22493 does not cover this graph, which has no earlier import of the same source).

System Info

Vite 8.3.8, 8.4.0-beta.1, 7.3.8
Node 26.12.1, Linux x64

Used Package Manager

npm

Activity

  1. abhi478jeetur-rgb commented on Nov 23, 2026

    @abhi478jeetur-rgb

    Reproduced on 8.3.8 with your exact files — Node gives { fromA: 42, fromB: 42 }, Vite gives { fromA: 42, fromB: undefined }, and after the load b.js's namespace keys are [] in Vite vs ['value'] in Node.

    Your likely spot is right. exportAll in module-runner.js copies the source's keys once, when the export * statement runs, defining a live getter per key. In this graph a.js starts evaluating first; its export * from './b.js' starts b.js, and b.js's export * from './a.js' runs while a.js still has no keys — its own export * from './leaf.js' hasn't run yet — so nothing is copied, and nothing ever re-runs exportAll for b.js afterwards. a.js picks up value later because by the time its export * from './leaf.js' runs, leaf has evaluated.

    So the copy is a snapshot of the keys at that moment, not the live binding set star exports are supposed to be. The getter it defines does read live (get: () => sourceModule[key]), but only for keys that existed when it ran. A fix would need b.js's namespace to gain the key when a.js gains it afterwards — either re-running the copy when the source module finishes evaluating, or resolving the re-export lazily so the key appears once the source has it.

  2. added a commit that references this issue on Nov 26, 2026
    ba1d99e
  3. added theissue type on Nov 26, 2026
  4. added
    p3-downstream-blocker
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: ssrp3-downstream-blocker

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions