Skip to content

Bundler: Bundler can emit self importing modules #21642

@andylovescode

Description

@andylovescode

What version of Bun is running?

v1.2.19 (aad3abe)

What platform is your computer?

Microsoft Windows NT 10.0.26100.0 x64

What steps can reproduce the bug?

e0.ts

function export_e3() {}
function export_e4() {}
function export_e5() {}
import { export_e8 } from "./e2";
const { export_e6 } = await import("./e1");
export { export_e3, export_e4, export_e5, export_e8, export_e6 };

e1.ts

function export_e6() {}
export { export_e6 };

e2.ts

function export_e7() {}
function export_e8() {}
const { export_e6, export_e4  } = await import("./e0");
export_e6();
export_e4();
export { export_e7, export_e8, export_e6 };

Entrypoints

  • e0.ts
  • e1.ts

What is the expected behavior?

I'd expect everything to just work fine.

What do you see instead?

In the generated output of e0.js, the module ends up importing itself to get export_e6, which returns undefined.

import {
  __require,
  __toESM
} from "./chunk-cf4g1482.js";

// trials/01987c9a-14d9-7000-81eb-c7064f2dfc79/codegen/e2.ts
function export_e8() {}
var { export_e6, export_e4 } = await import("./e0.js");
export_e6();
export_e4();
export_e6();
export_e6();

// trials/01987c9a-14d9-7000-81eb-c7064f2dfc79/codegen/e0.ts
function export_e3() {}
function export_e42() {}
function export_e5() {}
var { export_e6: export_e62 } = await import("./e1.js");
export {
  export_e8,
  export_e62 as export_e6,
  export_e5,
  export_e42 as export_e4,
  export_e3
};

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbundlerSomething to do with the bundler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions