8000 [BUG] Prisma throws `Error: [unenv] fs.readdir is not implemented yet!` when querying · Issue #623 · opennextjs/opennextjs-cloudflare · GitHub
[go: up one dir, main page]

Skip to content

[BUG] Prisma throws Error: [unenv] fs.readdir is not implemented yet! when querying #623

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

Closed
schweetheart opened this issue Apr 30, 2025 · 23 comments · Fixed by #628
Closed
Labels
bug Something isn't working triage

Comments

@schweetheart
Copy link
schweetheart commented Apr 30, 2025

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.

@schweetheart schweetheart added bug Something isn't working triage labels Apr 30, 2025
@vicb
Copy link
Contributor
vicb commented Apr 30, 2025

At least @prisma/client uses the workerd build condition.

Hopefully #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 #548 for some info. We will document that over the next few days.

Hope this helps

@schweetheart
Copy link
Author

Appreciate the quick response!

I've followed your suggestion and given the #593 binary a try and updated serverExternalPackages with the related packages, however am still getting the same error message. Have I missed some config somewhere?

// `@prisma/client` and `pg` are included in the Next.js serverExternalPackages list and should
//  automatically be opt-ed out
// https://github.com/vercel/next.js/blob/canary/packages/next/src/lib/server-external-packages.json
const nextConfig: NextConfig = {
  serverExternalPackages: ["@prisma/adapter-pg", "pg", "@prisma/client"],
};

Repro

@conico974
Copy link
Collaborator

No there is some other issue specific to prisma. Will have a PR for it tomorrow

@schweetheart
Copy link
Author

All working correctly for me after #628!

@vicb
Copy link
Contributor
vicb commented May 2, 2025

@schweetheart thanks for reporting and of course thanks to @conico974 for fixing that!

@Noitidart
Copy link
Noitidart commented Jun 15, 2025

Even with #628 it's not working for me. I even tried upgrading to latest "@opennextjs/cloudflare": "^1.3.0", I get the same readdir issue.

@Noitidart
Copy link

I have created a minimum reproducible - https://github.com/Noitidart/prisma-fail-cf-workers-nextjs

Can try running npm run preview and then hitting http://localhost:8787/api/hello and you will see:

{
  "name": "Error",
  "error": "[unenv] fs.readdir is not implemented yet!"
}

I attached a .env.sample but can change that to any connection url.

@BearTyree
Copy link
BearTyree commented Jun 16, 2025

I am having this same issue when attempting to use Prisma with cf workers and NextJs. Any updates? My repository is here: https://github.com/BearTyree/Flash-Royale I have the driver adapters enabled in my prisma schema, why is prisma trying to access the fs on the edge?

@sommeeeer
Copy link
Contributor
sommeeeer commented Jun 16, 2025

@BearTyree @Noitidart

Remember to add this to your next config:

const nextConfig: NextConfig = {
  // note both the `@prisma/client` and `.prisma/client`
  // you also want the adapters here
  serverExternalPackages: ["@prisma/adapter-neon", "@neondatabase/serverless", "@prisma/client", ".prisma/client"],
};

@Noitidart
Copy link

@sommeeeer
Copy link
Contributor
sommeeeer commented Jun 16, 2025

@Noitidart You are missing the .prisma/client in your next config. Note the dot (.)

@Noitidart
Copy link

Oh thank you! That fixed it!

@BearTyree
Copy link

@sommeeeer I tried adding all of this to my next.config.mjs. However, I am still getting the same error even after re-generating my prisma client and restarting the preview.

I have pushed all of the changes I have made to try and fix this to my repo: https://github.com/BearTyree/Flash-Royale
Am I missing anything?
My next.config.mjs looks like this:

import { setupDevPlatform } from "@cloudflare/next-on-pages/next-dev";

if (process.env.NODE_ENV === "development") {
  await setupDevPlatform();
}

/** @type {import('next').NextConfig} */
const nextConfig = {
  serverExternalPackages: [
    "@prisma/client",
    "@prisma/adapter-d1",
    ".prisma/client",
  ],
};

export default nextConfig;

import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";
initOpenNextCloudflareForDev();

@BearTyree
Copy link

@Noitidart are you doing anything other than that which is mentioned in this thread?

@Noitidart
Copy link

@BearTyree check out tat minimal repo I posted. With just adding .prisma/client it fixed it

@BearTyree
Copy link

@Noitidart Do you have any idea why this didn't work for my repo? Is d1 different?

@Noitidart
Copy link

I'm not sure.

@vuongphu
Copy link

@BearTyree check out tat minimal repo I posted. With just adding .prisma/client it fixed it

i tried check out and edit config but keep same error

@sommeeeer
Copy link
Contributor

@BearTyree check out tat minimal repo I posted. With just adding .prisma/client it fixed it

i tried check out and edit config but keep same error

Make sure to clean your folders before trying: rm -rf .next node_modules .wrangler .open-next.

Is you reproduction up-to-date?

@vuongphu
Copy link

@BearTyree check out tat minimal repo I posted. With just adding .prisma/client it fixed it

i tried check out and edit config but keep same error

Make sure to clean your folders before trying: rm -rf .next node_modules .wrangler .open-next.

Is you reproduction up-to-date?

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 .

@sommeeeer
Copy link
Contributor

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?

@vuongphu
Copy link

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] .

@sommeeeer
Copy link
Contributor
sommeeeer commented Jun 17, 2025

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.

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

Successfully merging a pull request may close this issue.

7 participants
0