SvelteKit (Vite) + D1 + Prisma Local development

I have a SvelteKit app that I'm developing with a D1 database accessed through Prisma.

I'm trying to run the Vite development server locally and have it connect to D1 locally.

My app works when deployed to workers (with experimental assets enabled), and can read/write from the D1 database via Prisma.

The code to initialize my database connection is:

import { PrismaClient } from '@prisma/client';
import { PrismaD1 } from '@prisma/adapter-d1';
import { env } from '$env/dynamic/private';

const adapter = new PrismaD1(env.DB);
const prisma = new PrismaClient({ adapter });
export default prisma;


Running locally, I typically run vite dev --host

Is there a way to get vite dev running so that it can access a local D1 Instance provided by Wrangler?

If not, is there a way to get that running so that my local dev environment could write to a real/hosted D1 instance that I specify?

Let me know if there's other info that could be helpful
Was this page helpful?