bun
bun copied to clipboard
Module build failed: UnhandledSchemeError: Reading from "bun:sqlite" is not handled by plugins (Unhandled scheme).
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
I ran into this issue and I made https://www.npmjs.com/package/@hebilicious/libsql-client while working on https://github.com/libsql/libsql-client-ts/pull/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)
Are you bundling with webpack? This looks like either a webpack or drizzle issue.
related thread in webpack repo https://github.com/webpack/webpack/issues/12792
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.
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 https://github.com/oven-sh/bun/issues/4795 for anyone who try to use Bun + Nextjs + Docker
@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 dev、 bun --bun run build
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
for anyone having issue, update the build script in your package.json into:
bunx --bun next build