Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark Bun built-ins as external #3398

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

colinhacks
Copy link

@colinhacks colinhacks commented Sep 20, 2023

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

@colinhacks colinhacks marked this pull request as ready for review September 20, 2023 01:07
@colinhacks colinhacks changed the title Mark bun: as external with platform=node Mark Bun built-ins as external Sep 20, 2023
@evanw
Copy link
Owner

evanw commented Sep 23, 2023

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.

@Jarred-Sumner
Copy link
Contributor

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.

@ersinakinci
Copy link

Any update on this? Or does anyone have workarounds?

@evanw
Copy link
Owner

evanw commented Apr 2, 2024

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:.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants