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

Module build failed: UnhandledSchemeError: Reading from "bun:sqlite" is not handled by plugins (Unhandled scheme). #4350

Closed
ImBIOS opened this issue Aug 26, 2023 · 7 comments
Labels
bug Something isn't working question Further information is requested

Comments

@ImBIOS
Copy link
Contributor

ImBIOS commented Aug 26, 2023

What version of Bun is running?

0.8.1

What platform is your computer?

Darwin 23.0.0 arm64 arm

What steps can reproduce the bug?

Try drizzle-orm with bun:sqlite example

import { drizzle, BunSQLiteDatabase } from 'drizzle-orm/bun-sqlite';
import { Database } from 'bun:sqlite';
 
const sqlite = new Database('sqlite.db');
const db: BunSQLiteDatabase = drizzle(sqlite);
 
const result = await db.select().from(users);

Reference: https://orm.drizzle.team/docs/installation-and-db-connection/sqlite/bun

What is the expected behavior?

It should run like we run normal sqlite, but blazingly fast 🔥 ⚡

What do you see instead?

- error bun:sqlite
Module build failed: UnhandledSchemeError: Reading from "bun:sqlite" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "bun:" URIs.
Import trace for requested module:
bun:sqlite
./src/server/db/index.ts
./src/server/auth.ts
./src/app/api/auth/[...nextauth]/route.ts

Additional information

Environment:


  System:
    OS: macOS 14.0
    CPU: (8) arm64 Apple M2
    Memory: 97.63 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.15.0 - ~/Library/Caches/fnm_multishells/29406_1693040511843/bin/node
    npm: 9.5.0 - ~/Library/Caches/fnm_multishells/29406_1693040511843/bin/npm
    pnpm: 8.6.12 - ~/Library/pnpm/pnpm
  Languages:
    Bash: 3.2.57 - /bin/bash
  npmPackages:
    @auth/drizzle-adapter: ^0.3.2 => 0.3.2 
    @commitlint/cli: ^17.7.1 => 17.7.1 
    @commitlint/config-conventional: ^17.7.0 => 17.7.0 
    @headlessui/tailwindcss: ^0.2.0 => 0.2.0 
    @radix-ui/react-dropdown-menu: ^2.0.5 => 2.0.5 
    @radix-ui/react-slot: ^1.0.2 => 1.0.2 
    @t3-oss/env-nextjs: ^0.6.1 => 0.6.1 
    @tanstack/react-query: ^4.33.0 => 4.33.0 
    @testing-library/jest-dom: ^6.1.2 => 6.1.2 
    @testing-library/react: ^14.0.0 => 14.0.0 
    @trivago/prettier-plugin-sort-imports: ^4.2.0 => 4.2.0 
    @trpc/client: ^10.38.0 => 10.38.0 
    @trpc/next: ^10.38.0 => 10.38.0 
    @trpc/react-query: ^10.38.0 => 10.38.0 
    @trpc/server: ^10.38.0 => 10.38.0 
    @types/eslint: ^8.44.2 => 8.44.2 
    @types/jest: ^29.5.4 => 29.5.4 
    @types/js-cookie: ^3.0.3 => 3.0.3 
    @types/node: ^20.5.6 => 20.5.6 
    @types/react: ^18.2.21 => 18.2.21 
    @types/react-dom: ^18.2.7 => 18.2.7 
    @typescript-eslint/eslint-plugin: ^6.4.1 => 6.4.1 
    @typescript-eslint/parser: ^6.4.1 => 6.4.1 
    @vercel/analytics: ^1.0.2 => 1.0.2 
    autoprefixer: ^10.4.15 => 10.4.15 
    bun: ^0.8.1 => 0.8.1 
    bun-types: ^0.8.1 => 0.8.1 
    class-variance-authority: ^0.7.0 => 0.7.0 
    clsx: ^2.0.0 => 2.0.0 
    dotenv: ^16.3.1 => 16.3.1 
    drizzle-kit: ^0.19.13 => 0.19.13 
    drizzle-orm: ^0.28.5 => 0.28.5 
    drizzle-zod: ^0.5.1 => 0.5.1 
    eslint: ^8.48.0 => 8.48.0 
    eslint-config-next: ^13.4.19 => 13.4.19 
    husky: ^8.0.3 => 8.0.3 
    jest: ^29.6.4 => 29.6.4 
    jest-environment-jsdom: ^29.6.4 => 29.6.4 
    js-cookie: ^3.0.5 => 3.0.5 
    lint-staged: ^14.0.1 => 14.0.1 
    lucide-react: ^0.269.0 => 0.269.0 
    next: ^13.4.19 => 13.4.19 
    next-auth: ^4.23.1 => 4.23.1 
    next-themes: ^0.2.1 => 0.2.1 
    postcss: ^8.4.28 => 8.4.28 
    prettier: ^3.0.2 => 3.0.2 
    prettier-plugin-tailwindcss: ^0.5.3 => 0.5.3 
    react: 18.2.0 => 18.2.0 
    react-dom: 18.2.0 => 18.2.0 
    superjson: 1.13.1 => 1.13.1 
    tailwind-merge: ^1.14.0 => 1.14.0 
    tailwindcss: ^3.3.3 => 3.3.3 
    tailwindcss-animate: ^1.0.6 => 1.0.6 
    typescript: ^5.2.2 => 5.2.2 
    zod: ^3.22.2 => 3.22.2 


@ImBIOS ImBIOS added the bug Something isn't working label Aug 26, 2023
@Hebilicious
Copy link

I ran into this issue and I made https://www.npmjs.com/package/@hebilicious/libsql-client while working on tursodatabase/libsql-client-ts#71

This works with drizzle :

import { drizzle } from "drizzle-orm/libsql"
import { createClient } from "@hebilicious/libsql-client"

const url = process.env.DATABASE_URL ?? "file:drizzle/local.db"
const authToken = process.env.DATABASE_AUTH_TOKEN

console.log(`Connecting to ${url}...`)
export const client = createClient({ url, authToken })
export const db = drizzle(client)

@Electroid
Copy link
Contributor

Are you bundling with webpack? This looks like either a webpack or drizzle issue.

@Electroid Electroid added the question Further information is requested label Oct 27, 2023
@rifaldhiaw
Copy link

related thread in webpack repo webpack/webpack#12792

@Jarred-Sumner
Copy link
Collaborator

To use bun:sqlite with webpack, bun:sqlite needs to be marked as external. Similar to how there is a node externals webpack plugin, there needs to be a bun externals webpack plugin.

@rifaldhiaw
Copy link

To use bun:sqlite with webpack, bun:sqlite needs to be marked as external. Similar to how there is a node externals webpack plugin, there needs to be a bun externals webpack plugin.

I see, got it. Tried to update

// next.config.js
module.exports = {
  webpack: (config) => {
    config.externals.push('bun:sqlite');
    return config;
  },
};

It worked in next dev. But having an issue when I try to build it.
Running bun run build (seems using nodejs)
will fail

Collecting page data  ..Error: Cannot find module 'bun:sqlite'

force running build in bun with bun run --bun build also failed:

Export encountered errors on following paths:
	/_error: /404
	...

seems related to this #4795
for anyone who try to use Bun + Nextjs + Docker

@gandli
Copy link

gandli commented Aug 27, 2024

@rifaldhiaw

// next.config.mjs

/** @type {import('next').NextConfig} */
const nextConfig = {
    webpack: (config) => {
        config.externals.push('bun:sqlite');
        return config;
    },
};

export default nextConfig;

Then, use bun --bun devbun --bun run build

@Jarred-Sumner
Copy link
Collaborator

This would be a bug in webpack/webpack config and not quite in Bun, though a "next-plugin-bun" would be a good solution for next for this

@gandli's solution should help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants