opennextjs-cloudflare: [BUG] Prisma throws `Error: [unenv] fs.readdir is not implemented yet!` when querying
Describe the bug
After following the Cloudflare workers with PostgreSQL tutorial.
When making a query via prisma client Error: [unenv] fs.readdir is not implemented yet! is thrown when running via the workers runtime pnpm preview.
When using a worker directly, Prisma works correctly.
// schema.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Post {
id Int @id @default(autoincrement())
title String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
// page.tsx
export default async function Home() {
// Force SSR
connection();
const connectionString = "example"
const adapter = new PrismaPg({ connectionString });
const prisma = new PrismaClient({ adapter });
const posts = await prisma.post.findMany();
return (
<div>
<div>{Date()}</div>
<div>{JSON.stringify(posts)}</div>
</div>
);
}
Steps to reproduce
- Clone the minimal reproduction
- Set
DATABASE_URLin .env and .dev.vars with a postgres compatible database. (I used Neon) - Preview the app locally via
pnpm preview - Visit
http://localhost:3000/ - You should see the error in the dialog.
Expected behavior
When running prisma directly in a worker without OpenNext, with the same code the result is working. When running the same code with OpenNext, the error is thrown. Am I missing some configuration, or is there some unexpected behavior when the OpenNext build process interacts with Prisma.
@opennextjs/cloudflare version
1.0.0-beta.4
Wrangler version
4.14.0
next info output
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000
Available memory (MB): 16384
Available CPU cores: 8
Binaries:
Node: 20.11.1
npm: 10.8.1
Yarn: 1.22.19
pnpm: 9.15.0
Relevant Packages:
next: 15.3.1 // Latest available version is detected (15.3.1).
eslint-config-next: 15.3.1
react: 19.1.0
react-dom: 19.1.0
typescript: 5.8.3
Next.js Config:
output: N/A
Additional context
Setting PRISMA_CLIENT_FORCE_WASM=1 has had no effect. I also tested via the @prisma/adapter-neon adapter with the same error.
It looks like others have encountered the same error recently with different adapters.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 23 (2 by maintainers)
All working correctly for me after #628!
You should create a new issue with a minimal reproduction then.
@Noitidart You are missing the
.prisma/clientin your next config. Note the dot (.)No there is some other issue specific to prisma. Will have a PR for it tomorrow
At least
@prisma/clientuses theworkerdbuild condition.Hopefully https://github.com/opennextjs/opennextjs-cloudflare/pull/593 should help with that - it has not been released yet but you can try the OpenNext binary from the PR.
You have to add the workerd specific packages to
serverExternalPackages. See https://github.com/opennextjs/opennextjs-cloudflare/issues/548 for some info. We will document that over the next few days.Hope this helps