P
Prisma•5mo ago
AirmanEpic

Prisma is throwing __filename is not defined specifically in SST cron jobs

This is a weird issue, when I'm running prisma through SST's cron job, which I need in order to do database processing tasks, I get an error that says
__filename is not defined
and the cron job fails. I've tried a workaround with
import type { PrismaClient as PrismaClientType } from '@prisma/client';
import { createRequire } from 'module';

const require = createRequire(import.meta.url ?? __filename);
const { PrismaClient: PrismaClientImpl } = require('@prisma/client');
export class PrismaClient extends (PrismaClientImpl as typeof PrismaClientType) {}
import type { PrismaClient as PrismaClientType } from '@prisma/client';
import { createRequire } from 'module';

const require = createRequire(import.meta.url ?? __filename);
const { PrismaClient: PrismaClientImpl } = require('@prisma/client');
export class PrismaClient extends (PrismaClientImpl as typeof PrismaClientType) {}
but unfortunately this doesn't seem to disconnect the prisma client ever or something, and so I get errors down the line because there are too many prisma clients connected.
5 Replies
AirmanEpic
AirmanEpicOP•5mo ago
Sorry, correction, it's saying "Can't find module '@prisma/client'"
RaphaelEtim
RaphaelEtim•5mo ago
Hi @AirmanEpic 👋 Can you switch your Prisma Client import code to the code below?
import { PrismaClient } from '@prisma/client';
export const prisma = new PrismaClient();
import { PrismaClient } from '@prisma/client';
export const prisma = new PrismaClient();
AirmanEpic
AirmanEpicOP•5mo ago
this throws an error saying __filename not found that's why it was switched to the weird looking import also, o/ and thanks for the help
RaphaelEtim
RaphaelEtim•5mo ago
Can you share more information about the error it throws? At what point does this error surface
AirmanEpic
AirmanEpicOP•4mo ago
Error shows up on cron jobs using SST. Normally it works fine in SST but for some reason this specific situation breaks it. I'll sample the full error for you next time I can but it basically boils down to __filename not defined. I found a workaround somewhere that uses that alternative thing but that doesnt seem to work either @RaphaelEtim thanks for the help again Anyone know what's going on here?
Want results from more Discord servers?
Add your server