Issue with Prisma D1 Adapter and Cloudflare Workers: fs.readdir Not Implemented
I’m currently building a website using Next.js, and I am using Prisma ORM to manage a Cloudflare D1 database. However, I’ve encountered an issue.
Previously, when I was using Prisma to manage a PostgreSQL database with Next.js on Cloudflare Workers, everything worked perfectly. Recently, I wanted to switch to using Cloudflare’s D1 database, but I’ve run into a problem.
4 Replies
Skipping coffee for instant knowledge! Let's brew that AI answer now.
To use Next.js with Cloudflare Workers, I need to use the @opennextjs/cloudflare package. My current setup looks like this:
However, when I initialize the Prisma client, I get the following error:
Previously, when using Prisma, I would run bun prisma generate --no-engine to generate the client, but with the adapter, this command is not allowed. Now, I can only run bun prisma generate to generate the client, but Cloudflare Workers do not support the
fs.readdir
API.
I’m wondering if anyone has encountered this issue or can point me in the right direction to solve this problem. Any help would be greatly appreciated!Based on the knowledge sources, there are several known issues when using Prisma with Cloudflare D1, particularly in edge environments like Cloudflare Workers.
The error you're encountering with
fs.readdir Not Implemented
is likely related to how Prisma tries to access the filesystem in edge environments. This is a common issue because edge runtimes like Cloudflare Workers don't have full Node.js filesystem access.
There are a few potential solutions:
1. Use the latest Prisma version with driver adapters: Make sure you're using Prisma v5.16.0 or newer with the D1 adapter properly configured:
2. Check your schema.prisma configuration: Ensure you have the proper configuration:
3. Externalize Prisma in your build: If you're using Vite to build your Cloudflare Pages project, you might need to externalize Prisma during the build process as mentioned in this GitHub issue:
4. Memory leak issues: Be aware that there are reported memory leak issues when using driver adapters with Cloudflare D1.
If you continue to face issues, you might want to consider using Prisma Accelerate as an alternative approach, which is specifically designed for edge environments.
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.I assume this discord conversation is related to this discussion?
https://github.com/prisma/prisma/discussions/27041
GitHub
Issue with Prisma D1 Adapter and Cloudflare Workers: fs.readdir Not...
Question I’m currently building a website using Next.js, and I am using Prisma ORM to manage a Cloudflare D1 database. However, I’ve encountered an issue. Previously, when I was using Prisma to man...