Hi Netlify,
Application is building fine, and deployment is successful, however app is down because of Edge function crash. Error message in logs is not much informative:
TypeError: WebAssembly.Instance(): Argument 0 must be a WebAssembly.Module
at file:///root/.netlify/edge-functions/___netlify-edge-handler-src-middleware/server/src/middleware.js:454:880
at async Object.loadLibrary (file:///root/.netlify/edge-functions/___netlify-edge-handler-src-middleware/server/src/middleware.js:454:1120)
at async rJ.loadEngine (file:///root/.netlify/edge-functions/___netlify-edge-handler-src-middleware/server/src/middleware.js:454:2928)
at async rJ.instantiateLibrary (file:///root/.netlify/edge-functions/___netlify-edge-handler-src-middleware/server/src/middleware.js:454:2524)
I guess it’s related to Prisma usage on edge. From This edge function has crashed as I understand Netlify doesn’t support Prisma edge.
Tech stack where we have problem is: NextJS 14 (app router), AuthJS, Prisma, Neon
Prisma schema (important part):
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
engineType = "library"
}
Prisma instance creation:
import { Pool } from "@neondatabase/serverless";
import { PrismaNeon } from "@prisma/adapter-neon";
import { PrismaClient } from "@prisma/client";
const connectionString = process.env.DATABASE_URL;
const pool = new Pool({ connectionString });
const adapter = new PrismaNeon(pool);
let prisma: PrismaClient;
export type Transaction = Omit<
PrismaClient,
"$connect" | "$disconnect" | "$on" | "$transaction" | "$use"
>;
if (typeof globalThis.prisma === "undefined") {
prisma = new PrismaClient({ adapter });
if (process.env.NODE_ENV === "development") {
globalThis.prisma = prisma; // For reuse in development to avoid multiple instances
}
} else {
prisma = globalThis.prisma;
}
export { prisma as db };
Auth config:
import type { JWT } from "@auth/core/jwt";
import { PrismaAdapter } from "@auth/prisma-adapter";
import type { UserRole } from "@prisma/client";
import NextAuth from "next-auth";
import { cookies } from "next/headers";
import authConfig from "@/auth.config";
import { getUserById } from "@/data/user";
import { db } from "@/lib/db";
export const {
handlers: { GET, POST },
auth,
signIn,
signOut,
unstable_update: update,
} = NextAuth({
secret: process.env.AUTH_SECRET,
pages: {
signOut: "/auth/sign-out",
signIn: "/auth/sign-in",
error: "/auth/error",
},
events: {
async linkAccount({ user }) {...},
},
callbacks: {
async signIn({ user, account }) {...},
async session({ session, ...sessionToken }) {...},
async jwt({ token, user }) {...},
},
adapter: PrismaAdapter(db),
session: { strategy: "jwt" },
...authConfig,
});
Questions:
- Is there paln for Netlify to support Prisma on edge?
- Is it possible to get more clear information on edge function log to understand that it’s because of Prisma? Logs are not descriptive enough
- Is there any workaround to make it work on edge?