Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next.js application with Prisma ORM and Neon Datasource

Tags:

next.js

prisma

I am struggling hard to connect to a neon database from a vercel edge function using a prisma client. After searching through the docs, I found out that neon has a serverless driver. I tried to use it how it is specified in the docs:

"use server";

import { Pool, neonConfig } from "@neondatabase/serverless";
import { PrismaNeon } from "@prisma/adapter-neon";
import { PrismaClient } from "@prisma/client";
import ws from "ws";

export const createPost = async (userId: string, content: string) => {
  neonConfig.webSocketConstructor = ws;
  const connectionString = `${process.env.DATABASE_URL}`;

  const pool = new Pool({ connectionString });
  const adapter = new PrismaNeon(pool);
  const prisma = new PrismaClient({ adapter });

  await prisma.post.create({
    data: {
      userId: userId,
      content: content,
    },
  });

  await prisma.$disconnect();

  await pool.end();
};

However, I keep getting this error: SyntaxError: Unexpected identifier 'Promise' at webpack_require. Does anyone know how to resolve this error?

like image 445
Lenny Avatar asked Dec 22 '25 02:12

Lenny


1 Answers

Would love to know if there's a fix for this, struggling with the same error to run Prisma from the edge with the Neon serverless driver.

like image 110
Sprouter Avatar answered Dec 29 '25 21:12

Sprouter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!