esbuild
esbuild copied to clipboard
Mark Bun built-ins as external
Users of various Vite-based frameworks have been hitting module resolution errors when trying Bun's built-in modules like bun:sqlite
. These frameworks generally rely on esbuild's default behavior of marking Node.js built-ins as external & side-effect-free. This PR does the same for Bun's built-ins: bun:*
modules and bun
itself.
Happy to update this to explicitly list each Bun builtin: bun:test
, bun:ffi
, bun:sqlite
, etc. But we'll likely update this list several times in the future and I was worried about maintainence burden for esbuild. So currently this PR just checks for the bun:
prefix. Unlike Node.js, Bun requires usage of the bun:
prefix for its built-in modules.
Some of the issues this fixes
- https://github.com/oven-sh/bun/issues/4761
- https://github.com/oven-sh/bun/issues/4704
- https://github.com/withastro/astro/issues/8476
- https://github.com/vitejs/vite/issues/14351
- https://github.com/oven-sh/bun/issues/4704
I'm not sure this specific direction (adding bun-specific stuff to esbuild's node target) makes sense because that target is for node, not bun.
I'm not sure this specific direction (adding bun-specific stuff to esbuild's node target) makes sense because that target is for node, not bun.
Bun is intended as a drop-in replacement for Node, so if anything in the node
target does not work in Bun, it would be a bug in Bun (and not esbuild). A bun
target would be more maintenance work for esbuild and would mean existing projects would need to change their esbuild configuration to fully support Bun.
Any update on this? Or does anyone have workarounds?
I'm not sure if this will work for you, but FYI esbuild already has an API to mark things as external: https://esbuild.github.io/api/#external. Specifically --external:bun:* --external:bun
will mark bun
as external as well as anything starting with bun:
.