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

Not able to resolve bun:* packages #14351

Closed
7 tasks done
andrioid opened this issue Sep 11, 2023 · 0 comments · Fixed by #14379
Closed
7 tasks done

Not able to resolve bun:* packages #14351

andrioid opened this issue Sep 11, 2023 · 0 comments · Fixed by #14379

Comments

@andrioid
Copy link

andrioid commented Sep 11, 2023

Describe the bug

I was playing with SSR on Astro (uses Vite) with Bun, and as soon as I try importing anything that uses the Bun API, like "bun:sqlite" it fails to resolve with the following error...

error   Cannot find module 'bun:sqlite' imported from '/home/andri/git/event-puffin-astro/src/lib/db/index.ts'
Error: Cannot find module 'bun:sqlite' imported from '/home/andri/git/event-puffin-astro/src/lib/db/index.ts'
    at nodeImport (file:///home/andri/git/event-puffin-astro/node_modules/vite/dist/node/chunks/dep-df561101.js:56010:25)
    at ssrImport (file:///home/andri/git/event-puffin-astro/node_modules/vite/dist/node/chunks/dep-df561101.js:55912:30)
    at eval (/home/andri/git/event-puffin-astro/src/lib/db/index.ts:3:50)
    at instantiateModule (file:///home/andri/git/event-puffin-astro/node_modules/vite/dist/node/chunks/dep-df561101.js:55974:15)

I found someone with a similar problem on the Astro issue tracker.

I went digging, and found the following snippet in nodeResolver() in Vite. I'm not that familiar with Vite's code-base, but I'd assume adding id.startsWith('bun:') there would fix the problem.

async function nodeImport(
  id: string,
  importer: string,
  resolveOptions: InternalResolveOptionsWithOverrideConditions,
) {
  let url: string
/* WE NEED TO ADD BUN HERE */
  if (id.startsWith('node:') || id.startsWith('data:') || isBuiltin(id)) {
    url = id
  } else {
    // Internal Vite resolution stuff. Uses node-resolve Rollup plugin.
}

Reproduction

Astro + Bun

Steps to reproduce

No response

System Info

Astro 3 (latest)
Bun 1 (latest) as runtime, and package manager

Used Package Manager

npm

Logs

No response

Validations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
1 participant