#Internal server error: Cannot find module 'bun:sqlite'

17 messages · Page 1 of 1 (latest)

fluid pier
#

Hello I am trying to test out bun:sqlite on qwik server side, but I cannot find the bun:sqlite module. I have added the bun-types to ts-config, but I still get these errors.

Does anyone know how to make this work?

fluid pier
#

I can build and serve and I get no errors and seem to work if I add this to the vite.config.ts for the bun adapter.

build: {
  ssr: true,
  rollupOptions: {
    input: ["src/entry.bun.ts", "@qwik-city-plan"],
    external: ['bun:sqlite']
  },
  minify: true,
},

However, if I add this in the vite.config.ts that is being run when starting, it has no effect and I still get the errors.

tawdry swan
fluid pier
#

Hi! Thanks for the answer.
I tried adding:

optimizeDeps: {
  exclude: ['bun:*']
},

But I still get errors:

Pre-transform error: Failed to load url bun:sqlite (resolved id: bun:sqlite) in /node_modules/mytestdb/service/db.js. Does the file exist?

:36:08 PM [vite] Error when evaluating SSR module /node_modules/mytestdb/service/db.js: failed to import "bun:sqlite"

I wonder if vite does not read the types that are defined in the tsconfig...

#

If I import the package dynamically in a function:

export init = () => { const sqlite = await import('bun:sqlite'); // No SSR evaluating errors }

tawdry swan
fluid pier
#

This is put in the vite.config.ts in qwik root.

#

Does not seem to work.

#

Also i notice when I load it dynamically I don't get the evaluating errors, but i still get error when i load it:

#

I tried
bun --bun run vite

But then I get errors with node, like crypto.

However, if I build and run serve with the bun adapter it works.

#
🐼 error [❌] Error: Cannot find module 'bun:sqlite' imported from 'node_modules/mytestdb/service/db.js'
    at nodeImport (file:///node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:54928:25)
    at ssrImport (file:///node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:54837:30)
    at ssrDynamicImport (file:///node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:54870:16)
    at Module.get (node_modules/mytestdb/service/db.js:11:33)
    at Module.vssSearch (node_modules/mytestdb/service/products.js:8:38)
    at Module.search (node_modules/mytestdb/index.js:25:48)
    at Object.eval (src/root.tsx:78:35)
    at Object.invokeApply (node_modules/@builder.io/qwik/core.mjs:3627:22)
    at Object.invoke (node_modules/@builder.io/qwik/core.mjs:3620:22)
    at eval (node_modules/@builder.io/qwik/core.mjs:7206:25)
6:04:14 PM [vite] ✨ new dependencies optimized: system-styles/panda/css, @agapi/panda/jsx

Looks maybe this is related to pandacss?

#

I have removed panda now.

I still get errors, the following:

file:///node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:54928
const err = new Error(Cannot find module '${id}' imported from '${importer}');
^

Error: Cannot find module 'bun:sqlite' imported from 'node_modules/mydbtest/service/db.js'
at nodeImport ...

tawdry swan
#

What is the error

fluid pier
#

The error I get now is when running vite:

[vite] Internal server error: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'bun:'
fluid pier
#

And when II build I get:

[vite]: Rollup failed to resolve import "bun:sqlite" from "/src/s_z0nr96c2cdw.js".
#

So it seems to be a problem with ESM-loader in vite? And rollup in vite?