I'm trying to use Prisma with neon/serverless from vercel. When I run npm run dev, I get this error message:
Argument of type 'Pool' is not assignable to parameter of type 'PoolConfig'.
Types of property 'options' are incompatible.
Type 'PoolOptions' is not assignable to type 'string'.
I tried all the available solutions and nothing was helpful, what I found was: the error means you’re passing a connection instance (Pool) where the code expects connection configuration (PoolConfig). but when I pass the connection configuration not the pool I get the error:
"Type 'string' has no properties in common with type 'PoolConfig'."
meaning: passing a string (connectionString) directly still triggers a type error. and you need to pass a PoolConfig object, not just a string!
import { Pool, neonConfig } from '@neondatabase/serverless';
import { PrismaNeon } from '@prisma/adapter-neon';
import { PrismaClient } from '@prisma/client';
import ws from 'ws';
// Sets up WebSocket connections, which enables Neon to use WebSocket communication.
neonConfig.webSocketConstructor = ws;
const connectionString = `${process.env.DATABASE_URL}`;
// Creates a new connection pool using the provided connection string, allowing multiple concurrent connections.
const pool = new Pool({ connectionString });
// Instantiates the Prisma adapter using the Neon connection pool to handle the connection between Prisma and Neon.
const adapter = new PrismaNeon(pool);
fields to strings.
export const prisma = new PrismaClient({ adapter }).$extends({
result: {
product: {
price: {
compute(product) {
return product.price.toString();
},
},
rating: {
compute(product) {
return product.rating.toString();
},
},
},
},
});
No need to create a Pool, just pass the connection string directly.
Here's what you are doing:
const connectionString = `${process.env.DATABASE_URL}`;
const pool = new Pool({ connectionString });
const adapter = new PrismaNeon(pool);
export const prisma = new PrismaClient({ adapter });
And here's what you should be doing:
const connectionString = `${process.env.DATABASE_URL}`;
const adapter = new PrismaNeon({ connectionString });
export const prisma = new PrismaClient({ adapter });
As you can see, we're skipping the Pool initiation step and just passing the connectionString to PrismaNeon class directly.
Also, for this feature, make sure you're using version 6.16.0 and higher.
For more details, see an example from official docs.