P
Prisma3mo ago
Corey

Turborepo x Prisma x Neon

Been stuck trying to implement a prisma database package for my monorepo (turborepo). I am using a neon driver adapter. I dont have any edge functions, besides middleware which just uses clerk. I get this error as soon as any page loads. It is an app router next js app btw that I am trying to use the prisma package in. ⨯ unhandledRejection: Error: dynamically loading WebAssembly is not supported in this runtime and global wasm_packages_database_prisma_generated_client_query_engine_bg_325b988e was not injected at <unknown> (packages/database/prisma/generated/client/query_enginebg.wasm.loader.mjs:3:18) at [project]/packages/database/prisma/generated/client/query_engine_bg.wasm?module [instrumentation-edge] (wasm module) (.next/server/edge/chunks/packages_database_prisma_generated_clientbf3ff1c7..j s:7165:1) at <unknown> (.next/server/edge/chunks/packages_database_prisma_generated_clientbf3ff1c7..js:7184:89) 1 | import wasmPath from "WASM_PATH"; 2 |
3 | const mod = await turbopack_wasm_module(wasmPath);
| ^ 4 | 5 | export default mod; 6 | I think I am just missing something critical and probably obvious.
1 Reply
Prisma AI Help
Prisma AI Help3mo ago
You chose to compile with the bot. One moment while I piece together your answer… Your error is due to Prisma’s WASM-based client not being supported in the Edge runtime (which includes Next.js middleware and Edge API routes). Even if you’re not using Edge functions directly, Next.js middleware always runs in the Edge runtime, and Prisma’s WASM client cannot be dynamically loaded there. This is a known limitation and is documented in several issues. Key points and solutions: - Prisma Client (with driver adapters like Neon) does not work in Edge runtimes. You’ll see errors about dynamic WASM loading or missing WASM modules, as you are experiencing. - For Edge runtimes, Prisma recommends: - Using Prisma Accelerate - Or using Driver Adapters (but only in Node.js, not Edge) - If you only use Prisma in API routes or server components (Node.js runtime), ensure you do not import or use Prisma in any middleware or Edge route handlers. - If you must use Prisma in middleware, it is not supported. You’ll need to refactor so that middleware does not touch the database, or use a different approach for those parts. References: - “Prisma Client is not configured to run in Edge Runtime… In order to run Prisma Client on edge runtime, either: Use Prisma Accelerate or Use Driver Adapters” Prisma issue #25930 - “Prisma cannot run on an edge environment… use an adapter like Neon or use prisma accelerate” Prisma issue #25930 - “dynamically loading WebAssembly is not supported in this runtime” and similar errors are reported when trying to use Prisma in Edge environments Prisma issue #24673 Summary:
You cannot use Prisma Client (even with Neon driver adapter) in Next.js middleware or any Edge runtime. Restrict your Prisma usage to Node.js server environments (API routes, se rver components) and avoid importing it in middleware. If you need database access in Edge, consider Prisma Accelerate or a different architecture. ✅ Great, thanks for letting us know that this solved your question!

Did you find this page helpful?