Guidance on migrating to Rust-free from TS?

We have a decently complex Prisma instantiation logic at the moment, but our bundle size is getting absolutely ridiculous at this point, our builds take ages to run and our IDEs are impossible to use so we really need to migrate from the Rust engine ASAP (our builds are failing). When I try to upgrade to the latest Prisma version, and start following the migratio - How do we handle our instatiation logic? We have a pretty complex setup here, and none of the examples really account for extension usage, typing, etc.
import type { Prisma } from '@prisma/client';
import { PrismaClient } from '@prisma/client';
import type { DynamicQueryExtensionArgs } from '@prisma/client/runtime/library';
import { readReplicas } from '@prisma/extension-read-replicas';
import { drizzle } from 'drizzle-orm/prisma/pg';

import { writeTriggersExtension } from './extensions/write-triggers/extension';
import { ensureDatabaseCert } from './prisma/certs';

declare const global: Global & {
prisma?: ReturnType<typeof createPrismaClient>;
prismaWithoutWriteTriggers?: ReturnType<typeof createPrismaClient>;
};

export let prisma: ReturnType<typeof createPrismaClient>;
export let prismaWithoutWriteTriggers: ReturnType<typeof createPrismaClient>;

export function createPrismaClient(
queryExtension?: DynamicQueryExtensionArgs<
{
[K in Prisma.TypeMap['meta']['modelProps'] | '$allModels']?: unknown;
},
Prisma.TypeMap
>,
options?: {
withWriteTriggers?: boolean;
},
) {
if (
process.env.DATABASE_URL &&
!process.env.DATABASE_URL.includes('localhost')
) {
ensureDatabaseCert();
}

const { withWriteTriggers = true } = options ?? {};
const client = new PrismaClient()
.$extends({
query: {
...(queryExtension ?? {}),
},
})
.$extends(withWriteTriggers ? writeTriggersExtension : {})
.$extends(drizzle());

// ALWAYS KEEP READ REPLICAS EXTENSION LAST THIS IS A LIMITATION OF THE PRISMA EXTENSION
return client.$extends({
...readReplicas({
url: [
process.env.DB_REPLICA_URL_1 ?? '',
process.env.DB_REPLICA_URL_2 ?? '',
],
}),
});
}

if (typeof window === 'undefined') {
if (process.env['NODE_ENV'] === 'production') {
prisma = createPrismaClient();

prismaWithoutWriteTriggers = createPrismaClient(undefined, {
withWriteTriggers: false,
});
} else {
if (!global.prisma) {
global.prisma = createPrismaClient();
}

if (!global.prismaWithoutWriteTriggers) {
global.prismaWithoutWriteTriggers = createPrismaClient(undefined, {
withWriteTriggers: false,
});
}

prisma = global.prisma;
prismaWithoutWriteTriggers = global.prismaWithoutWriteTriggers;
}
}
import type { Prisma } from '@prisma/client';
import { PrismaClient } from '@prisma/client';
import type { DynamicQueryExtensionArgs } from '@prisma/client/runtime/library';
import { readReplicas } from '@prisma/extension-read-replicas';
import { drizzle } from 'drizzle-orm/prisma/pg';

import { writeTriggersExtension } from './extensions/write-triggers/extension';
import { ensureDatabaseCert } from './prisma/certs';

declare const global: Global & {
prisma?: ReturnType<typeof createPrismaClient>;
prismaWithoutWriteTriggers?: ReturnType<typeof createPrismaClient>;
};

export let prisma: ReturnType<typeof createPrismaClient>;
export let prismaWithoutWriteTriggers: ReturnType<typeof createPrismaClient>;

export function createPrismaClient(
queryExtension?: DynamicQueryExtensionArgs<
{
[K in Prisma.TypeMap['meta']['modelProps'] | '$allModels']?: unknown;
},
Prisma.TypeMap
>,
options?: {
withWriteTriggers?: boolean;
},
) {
if (
process.env.DATABASE_URL &&
!process.env.DATABASE_URL.includes('localhost')
) {
ensureDatabaseCert();
}

const { withWriteTriggers = true } = options ?? {};
const client = new PrismaClient()
.$extends({
query: {
...(queryExtension ?? {}),
},
})
.$extends(withWriteTriggers ? writeTriggersExtension : {})
.$extends(drizzle());

// ALWAYS KEEP READ REPLICAS EXTENSION LAST THIS IS A LIMITATION OF THE PRISMA EXTENSION
return client.$extends({
...readReplicas({
url: [
process.env.DB_REPLICA_URL_1 ?? '',
process.env.DB_REPLICA_URL_2 ?? '',
],
}),
});
}

if (typeof window === 'undefined') {
if (process.env['NODE_ENV'] === 'production') {
prisma = createPrismaClient();

prismaWithoutWriteTriggers = createPrismaClient(undefined, {
withWriteTriggers: false,
});
} else {
if (!global.prisma) {
global.prisma = createPrismaClient();
}

if (!global.prismaWithoutWriteTriggers) {
global.prismaWithoutWriteTriggers = createPrismaClient(undefined, {
withWriteTriggers: false,
});
}

prisma = global.prisma;
prismaWithoutWriteTriggers = global.prismaWithoutWriteTriggers;
}
}
- We use Supabase, and there are no drivers for Supabase at the moment; what should we use here? If I use the pg adapter, I get the following build error:
@hou/web:build: Failed to compile.
@hou/web:build:
@hou/web:build: ../../node_modules/pg/lib/connection-parameters.js:3:1
@hou/web:build: Module not found: Can't resolve 'dns'
@hou/web:build:
@hou/web:build: https://nextjs.org/docs/messages/module-not-found
@hou/web:build:
@hou/web:build: Import trace for requested module:
@hou/web:build: ../../node_modules/pg/lib/client.js
@hou/web:build: ../../node_modules/pg/lib/index.js
@hou/web:build: ../../node_modules/@prisma/adapter-pg/dist/index.mjs
@hou/web:build: ../../packages/db/client.ts
@hou/web:build: ../../packages/common-services/src/utils/feature-gates.ts
@hou/web:build: ../../packages/common-services/src/utils/index.ts
@hou/web:build: ./src/components/application-review/cards/assignment/phase-reason-view.tsx
@hou/web:build: ./src/components/application-review/cards/assignment/assignment-phases.tsx
@hou/web:build: ./src/components/application-review/application-review.tsx
@hou/web:build: ./src/pages/admin/applicants/review/[[...ids]].tsx
@hou/web:build: Failed to compile.
@hou/web:build:
@hou/web:build: ../../node_modules/pg/lib/connection-parameters.js:3:1
@hou/web:build: Module not found: Can't resolve 'dns'
@hou/web:build:
@hou/web:build: https://nextjs.org/docs/messages/module-not-found
@hou/web:build:
@hou/web:build: Import trace for requested module:
@hou/web:build: ../../node_modules/pg/lib/client.js
@hou/web:build: ../../node_modules/pg/lib/index.js
@hou/web:build: ../../node_modules/@prisma/adapter-pg/dist/index.mjs
@hou/web:build: ../../packages/db/client.ts
@hou/web:build: ../../packages/common-services/src/utils/feature-gates.ts
@hou/web:build: ../../packages/common-services/src/utils/index.ts
@hou/web:build: ./src/components/application-review/cards/assignment/phase-reason-view.tsx
@hou/web:build: ./src/components/application-review/cards/assignment/assignment-phases.tsx
@hou/web:build: ./src/components/application-review/application-review.tsx
@hou/web:build: ./src/pages/admin/applicants/review/[[...ids]].tsx
2 Replies
Prisma AI Help
Prisma AI Help2mo ago
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
Nurul
Nurul2mo ago
I found a related GitHub Issue about the error you are reporting: https://github.com/prisma/prisma/issues/28096 It seems that the error occurs when Prisma Types are imported from wrong location
GitHub
./node_modules/@prisma/adapter-pg/dist/index.mjs [Client Component ...
Bug description Build Error Module not found: Can&#39;t resolve &#39;dns&#39; ./node_modules/pg/lib/connection-parameters.js (3:13) Module not found: Can&#39;t resolve &#39;dns&#39; 1 | &#39;use st...

Did you find this page helpful?