Skip to content

Code splitting cause optional export/module to be referenced by other modules #942

@fuma-nama

Description

@fuma-nama

Reproduction link or steps

https://stackblitz.com/edit/github-kuvn25tk

  1. Given 3 entries (a, b, c), they are all independent and do not reference each other.
  2. Define a shared folder, with two files: index.ts & build-content.ts.
  3. Let a and b import shared/index.ts, and c import shared/build-content.ts.
  4. Let shared/index.ts lazy import shared/build-content.ts.
  5. Install vitefu as dev dep, and ensure to bundle it, then reference it in entry a. (this can be any dep, this step is necessary)
  6. Run tsdown, notice that __exportAll is generated in dist/entry-a/index.js because vitefu's inlined bundle generating parts of rolldown/runtime.
  7. Notice that the shared file dist/build-content<hash>.js imports dist/entry-a/index.js, since it's a shared file, all entries now import entry a, problem caused.

What is expected?

When entry (a, b, c) are independent, their dependency relationship should not be changed and remain independent.

In reality, entry-a, entry-b entry-c could be adapters for different runtime/framework, e.g. /next, /tanstack-start, /react-router. This will cause runtime error as a React Router consumer using /react-router adapter will end up importing /next, which may import next and cause runtime error.

What is actually happening?

All entries are importing entry a, while they were originally independent.

Any additional comments?

I was confirming the current behaviour of rolldown based on https://github.com/rolldown/rolldown/blob/70c4828d616df5afabafbafc56ba2c9950fb460b/meta/design/code-splitting.md, but it took more time than I expected, couldn't narrow it down further sadly. Perhaps you might know more about the internals, thank you for the tsdown library :)

Metadata

Metadata

Assignees

No one assigned

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions