Prisma with Accelerate TypeScript error

When I'm using Prisma with Accelerate, the Prisma types are not generated for the Accelerate extension. Trying to use cacheStrategy results in TS showing the following error:
Type '{ ttl: number; }' is not assignable to type 'never'.ts(2322)
Type '{ ttl: number; }' is not assignable to type 'never'.ts(2322)
I'm using SvelteKit and have the following setup: src/app.d.ts:
import type { PrismaClient } from "@prisma/client";
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces

declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
var prisma: PrismaClient;
}

export {};
import type { PrismaClient } from "@prisma/client";
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces

declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
var prisma: PrismaClient;
}

export {};
src/lib/server/prisma.ts:
import { PrismaClient } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";

declare global {
var prisma: PrismaClient;
}

const prisma = global.prisma || new PrismaClient().$extends(withAccelerate());
global.prisma = prisma;

export default prisma;
import { PrismaClient } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";

declare global {
var prisma: PrismaClient;
}

const prisma = global.prisma || new PrismaClient().$extends(withAccelerate());
global.prisma = prisma;

export default prisma;
How can I fix this?
5 Replies
Nurul
Nurul•5mo ago
Hey @Woman wearing Vision Pro 👋 This is strange. To confirm, you invoked npx prisma generate command, right?
Woman wearing Vision Pro
Yes I have, multiple times even
Nurul
Nurul•5mo ago
Is your repository open source? If yes, can you share it with me so that I can try to reproduce and investigate?
Nurul
Nurul•5mo ago
I found a related discussion here: https://github.com/prisma/prisma/discussions/22489 Does your query work if you directly define prisma client in the file in which you are invoking the query. Something like new PrismaClient().$extends(withAccelerate()).your_model_name.findUnique({ cacheStrategy: ... })
GitHub
Cannot use cacheStrategy because of 'Never' type · prisma prisma · ...
Question I want to query like this: await this.prismaService.site.findFirst({ where: { url: siteDomain, seller_name: '', }, cacheStrategy: { ttl: 60 }, }); But I get this error: TS2322: Typ...
Woman wearing Vision Pro
It is open source but it's a pretty big project and requires a lot of external stuff to get it fully working. If you still want to take a look I'll send the repo. It's not that the query fails, it's that typescript is complaining, so it's more an annoyance than something that's preventing caching/executing queries. bump
Want results from more Discord servers?
Add your server