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>
  );
} 
Image

Steps to reproduce

  1. Clone the minimal reproduction
  2. Set DATABASE_URL in .env and .dev.vars with a postgres compatible database. (I used Neon)
  3. Preview the app locally via pnpm preview
  4. Visit http://localhost:3000/
  5. 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)

Most upvoted comments

All working correctly for me after #628!

i re install last package and update node , run dev it okay , but keep error in deploy and preview . i spend fews day run prisma + cloudflare worker , it no hope . now i using drizzle , it run well .

Prisma should work fine now for that adapter you are using. You most likely have something in your setup thats not right. Did you update your @opennextjs/cloudflare version aswell?

i tried from [1.0.0-beta.4] , [1.2.1] to [1.3.0] .

You should create a new issue with a minimal reproduction then.

@Noitidart You are missing the .prisma/client in 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/client uses the workerd build 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