-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Labels
Description
What version of Bun is running?
1.3.10+30e609e08
What platform is your computer?
Linux 6.19.6-arch1-1 x86_64 unknown
What steps can reproduce the bug?
https://github.com/eyenalxai/bun-bundle-bug-mre
This repository is a minimal workspace repro with three packages:
@mini-bug/utils@mini-bug/codec@mini-bug/repro
The relevant code shape is:
// packages/mini-bug-utils/src/index.ts
import * as typed from './arrays/typed/index.js'
import * as u8 from './arrays/u8/pool.js'
export { typed, u8 }// packages/mini-bug-utils/src/arrays/typed/index.ts
export { toDataView } from './misc.js'// packages/mini-bug-codec/src/network/transports/intermediate.ts
import { typed } from '@mini-bug/utils'
const view = typed.toDataView(output)// packages/mini-bug-repro/src/index.ts
import { u8 } from "@mini-bug/utils"
import { PaddedIntermediatePacketCodec } from "@mini-bug/codec"Commands:
bun install
bun run source
bun run bundle:run
bun run compile:runWhat they do:
"scripts": {
"source": "bun run ./src/index.ts",
"bundle:run": "bun build ./src/index.ts --outfile ./dist/index.js --target bun && bun run ./dist/index.js",
"compile:run": "bun build --compile --target=bun-linux-x64-modern ./src/index.ts --outfile ./dist/index && ./dist/index"
},Current results:
bun run sourcesucceedsbun run bundle:runfailsbun run compile:runfails
What is the expected behavior?
bun build --target bun and bun build --compile should preserve the same behavior as the source run.
Both generated outputs should run successfully and print:
14
8
What do you see instead?
ReferenceError: toDataView is not defined
bun run bundle:run:
Bundled 6 modules in 2ms
index.js 1.61 KB (entry point)
15 | };
16 |
17 | // ../mini-bug-utils/src/arrays/typed/index.ts
18 | var exports_typed = {};
19 | __export(exports_typed, {
ReferenceError: toDataView is not defined
at toDataView (/home/ulezot/Projects/js/bun-bundle-bug-mre/packages/mini-bug-repro/dist/index.js:20:31)
at encode (/home/ulezot/Projects/js/bun-bundle-bug-mre/packages/mini-bug-repro/dist/index.js:41:31)
at /home/ulezot/Projects/js/bun-bundle-bug-mre/packages/mini-bug-repro/dist/index.js:56:13
at loadAndEvaluateModule (2:1)
bun run compile:run:
[2ms] bundle 6 modules
[1ms] compile ./dist/index
15 | };
16 |
17 | // ../mini-bug-utils/src/arrays/typed/index.ts
18 | var exports_typed = {};
19 | __export(exports_typed, {
ReferenceError: toDataView is not defined
at toDataView (/$bunfs/root/index:20:31)
at encode (/$bunfs/root/index:41:31)
at /$bunfs/root/index:56:13
at loadAndEvaluateModule (2:1)
Additional information
The failure appears to depend on this combination:
- a namespace export from
@mini-bug/utils - a re-exported binding in
packages/mini-bug-utils/src/arrays/typed/index.ts - runtime access through
typed.toDataView(...)
Two changes both make the repro stop failing:
- Replace
export { toDataView } from './misc.js'with a direct local definition intyped/index.ts. - Bypass
typed/index.tsand import from./arrays/typed/misc.jsinstead.
That suggests the bundled output is creating a getter for the re-exported binding without preserving the matching binding definition.
Reactions are currently unavailable