Open felipemotarocha opened 1 month ago
I haven't tested this but if the linking SDK doesn't work for CJS, I would recommend not using links in this case and passing in the values as environment variables.
I don't know if we'll go back and add CJS support anytime soon.
Hey @jayair, thanks for the answer. I ended up moving the Lambdas back to ESM and adapting Prisma to work with it.
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) {}
declare global {
var cachedPrisma: PrismaClient
}
let prisma: PrismaClient
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient()
} else {
if (!global.cachedPrisma) {
global.cachedPrisma = new PrismaClient()
}
prisma = global.cachedPrisma
}
export { prisma }
Not a pretty code but it's working.
I have the following code:
This handler tries to write a message on the
admissionJourneyEventCreatedTopic
but a error is being thrown, even though the topic is linked:If I remove the
format: 'cjs'
property it works fine, but I can't do it since I'm using Prisma and Prisma needs to use the__filename
variable, which is only available in CommonJS modules.Can someone help me with this please?