Conversation
When code splitting is enabled and a file is both an entry point and
imported by another entry point, the bundler was generating duplicate
export statements. This happened because:
1. generateEntryPointTailJS generates exports for entry point's named exports
2. computeCrossChunkDependencies generates cross_chunk_suffix_stmts for
symbols that other chunks need to import
Both paths were adding export clauses to the output, resulting in invalid
JavaScript with duplicate `export { symbol }` statements.
The fix skips generating cross_chunk_suffix_stmts for entry point chunks
since generateEntryPointTailJS already handles their exports. The
exports_to_other_chunks map is still populated for the import side.
Fixes #10631
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
WalkthroughThis PR fixes duplicate exports generated by Changes
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@test/regression/issue/10631.test.ts`:
- Around line 25-28: The test currently awaits stdout, stderr and exitCode
together but asserts exitCode before checking stdout, making failures less
clear; update the assertions in the build blocks that use Promise.all([...])
(variables stdout, stderr, exitCode) so you assert stdout (and stderr if
expected) before asserting exitCode — i.e., add or move the expect(stdout)
assertion to come prior to expect(exitCode). Apply this change to the
occurrences around the Promise.all usage (the blocks at lines ~25-28, ~76-79,
and ~138-141).
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| expect(stderr).toBe(""); | ||
| expect(exitCode).toBe(0); |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Assert build stdout before exitCode for clearer failures.
This follows the test guideline and makes failures more actionable.
♻️ Proposed change (apply to each build block)
- const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
-
- expect(stderr).toBe("");
- expect(exitCode).toBe(0);
+ const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
+
+ expect(stdout).toBe("");
+ expect(stderr).toBe("");
+ expect(exitCode).toBe(0);As per coding guidelines, ...
Also applies to: 76-79, 138-141
🤖 Prompt for AI Agents
In `@test/regression/issue/10631.test.ts` around lines 25 - 28, The test currently
awaits stdout, stderr and exitCode together but asserts exitCode before checking
stdout, making failures less clear; update the assertions in the build blocks
that use Promise.all([...]) (variables stdout, stderr, exitCode) so you assert
stdout (and stderr if expected) before asserting exitCode — i.e., add or move
the expect(stdout) assertion to come prior to expect(exitCode). Apply this
change to the occurrences around the Promise.all usage (the blocks at lines
~25-28, ~76-79, and ~138-141).
Summary
export { symbol }statements when code splitting is enabled and a file is both an entry point and imported by another entry pointRoot Cause
When code splitting is enabled and a module is both:
Two separate code paths generate export statements:
generateEntryPointTailJSgenerates exports for entry point's named exportscomputeCrossChunkDependenciesgeneratescross_chunk_suffix_stmtsfor symbols that other chunks need to importBoth paths were adding export clauses to the output, resulting in:
Fix
Skip generating
cross_chunk_suffix_stmtsfor entry point chunks sincegenerateEntryPointTailJSalready handles their exports. Theexports_to_other_chunksmap is still populated for the import side to work correctly.Test plan
test/regression/issue/10631.test.tsUSE_SYSTEM_BUN=1and passes withbun bd testbun bd test test/bundler/bundler_splitting.test.ts)Fixes #10631
🤖 Generated with Claude Code