QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.84k stars 1.31k forks source link

[🐞] Cannot find module 'bun:sqlite' #5631

Closed henpa closed 4 months ago

henpa commented 11 months ago

Which component is affected?

Qwik Runtime

Describe the bug

I'm trying to use use and deploy qwik using Bun and it's sqlite libray "bun:sqlite", without success.

After bun create qwik@latest and selecting Empty App, I replaced the src/routes/index.tsx file with the content below:

import { component$ } from "@builder.io/qwik";
import { server$ } from "@builder.io/qwik-city";
import { Database } from "bun:sqlite";

const servertest = server$((text: string) => {
  console.log(text);
  const db = new Database(":memory:");
  const query = db.query("create table foo;");
  query.run;
  return "hello from server";
});

export default component$(() => {
  return (
    <>
      <h1>Hi 👋</h1>
      <button
        onClick$={async () => {
          const greeting = await servertest("hello from client");
          console.log(greeting);
        }}
      >
        greet
      </button>
    </>
  );
});

When I run bun start I get the error: [vite] Internal server error: Cannot find module 'bun:sqlite' imported from '/Users/me/test1/src/routes/index.tsx'

Trying to deploy using Bun didn't work either. This is what I tried.

First, added the integration: bun run qwik add bun I also installed Bun's types with bun install -d bun-types and added "bun-types" to compilerOptions.types in tsconfig.js

And when I try to run bun run build I get this error: [vite]: Rollup failed to resolve import "bun:sqlite" from "/Users/henpa/dev/test1/src/routes/index.tsx". This is most likely unintended because it can break your application at runtime. If you do want to externalize this module explicitly add it to build.rollupOptions.external

Then I tried to add to vite.config.ts the following:

    build: {
      rollupOptions: {
        external: ["bun:sqlite"]
      }
    },

When I run bun run build again I get this error: Error [PLUGIN_ERROR]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'bun:'

Is it possible to run and deploy to Bun and use bun:sqlite? Thanks!

Reproduction

https://github.com/henpa/test1

Steps to reproduce

bun create qwik@latest bun start bun run qwik add bun

System Info

System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M2
    Memory: 2.46 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - /usr/local/bin/node
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.10.5 - ~/Library/pnpm/pnpm
    bun: 1.0.18 - ~/.bun/bin/bun
  Browsers:
    Chrome: 120.0.6099.109
    Safari: 17.2.1
  npmPackages:
    @builder.io/qwik: ^1.3.1 => 1.3.1 
    @builder.io/qwik-city: ^1.3.1 => 1.3.1 
    undici: ^5.26.0 => 5.28.2 
    vite: ^5.0.6 => 5.0.10

Additional Information

No response

gioboa commented 10 months ago

Hi @henpa this issue https://github.com/vitejs/vite/issues/14351 is a similar one 🤔

gioboa commented 5 months ago

@henpa Did you solve this issue?

github-actions[bot] commented 5 months ago

Hello @henpa. Please provide the missing information requested above. Issues marked with STATUS-2: missing info will be automatically closed if they have no activity within 14 days. Thanks 🙏