-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
What version of Bun is running?
Bun 1.3.10 (regression from 1.3.9)
What platform is your computer?
Darwin 25.2.0 arm64 arm
What steps can reproduce the bug?
mkdir repro && cd repro// a.ts
import { createContext, createElement, useContext } from "react"
const Ctx = createContext(null)
function Root({ children }) {
return createElement(Ctx.Provider, { value: {} }, createElement("div", null, children))
}
function Trigger({ children }) {
const ctx = useContext(Ctx)
return createElement("button", null, children)
}
export const A = { Root, Trigger }// b.ts
import { createContext, createElement, useContext } from "react"
const Ctx = createContext(null)
function Root({ children }) {
return createElement(Ctx.Provider, { value: {} }, createElement("div", null, children))
}
function Trigger({ children }) {
const ctx = useContext(Ctx)
return createElement("button", null, children)
}
export const B = { Root, Trigger }// index.ts
export { A } from "./a.js"
export { B } from "./b.js"// package.json
{ "name": "test", "type": "module", "sideEffects": ["./dist/index.js"] }bun build index.ts --outdir out --format esm --external react --minify
cat out/index.jsWhat is the expected behavior?
Bundled 3 modules in 2ms
index.js 0.76 KB
Full output with all function bodies and correct exports.
What do you see instead?
Actual (Bun 1.3.10):
Bundled 1 module in 2ms
index.js 61 bytes
export{l as B,t as A};Variables l and t are never declared, the bundler tree-shook away all module contents.
Additional information
Summary: Bun.build() / bun build incorrectly applies the sideEffects field from the project's own package.json to source files during bundling. This causes the bundler to tree-shake away all re-exported modules, producing an empty output with dangling export references.
Root cause: The bundler reads the sideEffects field from the project's own package.json and applies it to source files during the build. Since ./dist/index.js doesn't match any source file path, the bundler treats all source modules as side-effect-free and drops them entirely. The sideEffects field is intended for downstream consumers, not for the package's own build process.