Fix duplicate exports when two entrypoints share symbols (#26089)

### What does this PR do?

Fixes #5344
Fixes #6356

### How did you verify your code works?

Some test coverage

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude Bot <claude-bot@bun.sh>
This commit is contained in:
Alistair Smith
2026-01-20 12:40:33 -08:00
committed by GitHub
parent 66d8397bd7
commit 497a4d4818
9 changed files with 131 additions and 9 deletions

View File

@@ -279,7 +279,6 @@ describe("bundler", () => {
},
});
itBundled("splitting/ReExportESBuildIssue273", {
todo: true,
files: {
"/a.js": `export const a = { value: 1 }`,
"/b.js": `export { a } from './a'`,
@@ -609,4 +608,28 @@ describe("bundler", () => {
stdout: "42 true 42",
},
});
// Test that CJS modules with dynamic imports to other CJS entry points work correctly
// when code splitting causes the dynamically imported module to be in a separate chunk.
// The dynamic import should properly unwrap the default export using __toESM.
// Regression test for: dynamic import of CJS chunk returns { default: { __esModule, ... } }
// and needs .then((m)=>__toESM(m.default)) to unwrap correctly.
// Note: __esModule is required because bun optimizes simple CJS to ESM otherwise.
itBundled("splitting/CJSDynamicImportOfCJSChunk", {
files: {
"/main.js": /* js */ `
import("./impl.js").then(mod => console.log(mod.foo()));
`,
"/impl.js": /* js */ `
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = () => "success";
`,
},
entryPoints: ["/main.js", "/impl.js"],
splitting: true,
outdir: "/out",
run: {
file: "/out/main.js",
stdout: "success",
},
});
});