oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.18k stars 2.77k forks source link

[bundler] circular dynamic import cause "Duplicated export" #7521

Open codehz opened 11 months ago

codehz commented 11 months ago

What version of Bun is running?

1.0.15+b3bdf22eb

What platform is your computer?

Darwin 23.1.0 arm64 arm

What steps can reproduce the bug?

https://replit.com/@codehz/bun-build-bug-repro

//a.ts
export const a = 1;
import("./b")

//b.ts
import { a } from "./a"
export const b = a;

//index.ts
Bun.build({
  entrypoints: ["./a.ts", "./b.ts"],
  outdir: "./dist",
})

What is the expected behavior?

no runtime error

What do you see instead?

output a.js:

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getProtoOf = Object.getPrototypeOf;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __toESM = (mod, isNodeMode, target) => {
  target = mod != null ? __create(__getProtoOf(mod)) : {};
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
  for (let key of __getOwnPropNames(mod))
    if (!__hasOwnProp.call(to, key))
      __defProp(to, key, {
        get: () => mod[key],
        enumerable: true
      });
  return to;
};
var __require = (id) => {
  return import.meta.require(id);
};

// a.ts
var a = 1;
import("./b.js");
export {
  a
};

export { a };

Additional information

No response

tobowers commented 11 months ago

In fact, it doesn't even need to be circular: https://replit.com/@topper2/bun-build-bug-repro-no-circular#dist-c/c.js