sst: Prisma example is broken since SST 2.0

I tried to setup a new project using the prisma example, but it does not seem to work with sst2.0

Command: yarn create sst --template=examples/prisma

When running a function that uses a prismaClient instance you receive an error: Your schema.prisma could not be found, and we detected that you are using Next.js I assume this is because sst is now a monorepo and prisma has some issues with monorepos and needs a workaround to function with nextjs as discussed in their documentation: https://www.prisma.io/docs/guides/database/troubleshooting-orm/help-articles/nextjs-prisma-client-monorepo#problem

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 7
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I’m waiting on a fix from prisma since recent versions refuse to find the schema.prisma file when used with SST

@perfectbase I made a repo that I posted about on the the SST discord. Here it is: https://github.com/geauser/sst-prisma-example

You should join the discord as well most people ask questions over there!

Something that has fixed the schema.prisma not being found issue for me (at least locally - I haven’t tested deploying it yet) was to bundle the external libraries all the time ie.

- external: app.local ? [] : ['@prisma/client', '.prisma']

+ external: ['@prisma/client', '.prisma']

Also, I discovered that if you specify the output path in your schema.prisma file and then try to import the types, client etc. in a separate module and then try to use that module in your apps, it’ll break too with the __filename error. To go around this issue, remove the output path and inside the module that you’ll import all over your apps, just export @prisma/client.

@revmischa any updates on this, we have been struggling with prisma and sst for a while.

Yeah sst-prisma is updated https://github.com/jetbridge/sst-prisma

When running a lambda that accesses a prismaClient instance the following error occurs:

2023-03-29T15:10:57.786Z	undefined	ERROR	Uncaught Exception 	{
    "errorType": "Error",
    "errorMessage": "ENOENT: no such file or directory, open '/var/task/services/api/functions/schema.prisma'",
    "code": "ENOENT",
    "errno": -2,
    "syscall": "open",
    "path": "/var/task/services/api/functions/schema.prisma",
    "clientVersion": "4.12.0",
    "stack": [
        "Error: ENOENT: no such file or directory, open '/var/task/services/api/functions/schema.prisma'",
        "    at Object.openSync (node:fs:590:3)",
        "    at Object.readFileSync (node:fs:458:35)",
        "    at new LibraryEngine (file:///var/task/services/api/functions/index.mjs:29805:39)",
        "    at t3.getEngine (file:///var/task/services/api/functions/index.mjs:33428:20)",
        "    at new PrismaClient (file:///var/task/services/api/functions/index.mjs:33410:1118)",
        "    at file:///var/task/services/api/functions/index.mjs:58864:14",
        "    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)",
        "    at async Promise.all (index 0)",
        "    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)",
        "    at async _tryAwaitImport (file:///var/runtime/index.mjs:917:16)"
    ]
}

With prisma.schema copied to var/task/services/api/functions -> resolveEnginePath function of prisma accesses __filename which is not defined…

2023-03-29T15:29:12.684Z	fd320ee1-d78a-4e81-afe5-98f92c7e65ec	ERROR	ReferenceError: __filename is not defined
    at Object.resolveEnginePath (file:///var/task/services/api/functions/index.mjs:29737:58)
    at Object.getLibQueryEnginePath (file:///var/task/services/api/functions/index.mjs:29693:68)
    at Object.loadLibrary (file:///var/task/services/api/functions/index.mjs:29679:107)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.loadEngine (file:///var/task/services/api/functions/index.mjs:29865:58)
    at async Object.instantiateLibrary (file:///var/task/services/api/functions/index.mjs:29837:63)
    at async Object.start (file:///var/task/services/api/functions/index.mjs:29908:13)
    at async Object.getDmmf (file:///var/task/services/api/functions/index.mjs:29939:9)
    at async file:///var/task/services/api/functions/index.mjs:33385:24
    at async file:///var/task/services/api/functions/index.mjs:33391:186 {
  clientVersion: '4.12.0'
}