drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: Error resolving commonjs request for [project]/node_modules/better-sqlite3/lib/database.js

Open aretrace opened this issue 2 years ago • 0 comments

What version of drizzle-orm are you using?

0.21.1

Describe the Bug

I am attempting to use Next.js 13 new app directory (trying out RSCs) with drizzle-orm/better-sqlite3, I get the following error:

... warn - ./node_modules/better-sqlite3/lib/database.js Critical dependency: the request of a dependency is an expression ... Import trace for requested module: ./node_modules/better-sqlite3/lib/database.js ./node_modules/better-sqlite3/lib/index.js ./src/db/client.ts ./src/app/page.tsx error - Failed to generate static paths for /: TypeError: Cannot read properties of undefined (reading 'indexOf') ...

My codebase is a bare-bones skeleton:

src/ ├── app/ │ ├── ... │ ├── page.tsx │ └── ... └── db/ ├── ... ├── client.ts └── ...

In client.ts I export a const db from drizzle(...) api and I import it in page.tsx where I attempt to execute a simple query (trying both outside and inside the react component function), the error stems from the instantiation of better-sqlite3's new Database with nextjs displaying the following error in the browser:

Server Error TypeError: Cannot read properties of undefined (reading 'indexOf') ... export const db = new Database('sqlite.db') ^

I am fairly confident all statements are running only on the server (I used the 'use server' directive and get the same error). Am I missing something here?

aretrace avatar Mar 11 '23 08:03 aretrace