Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate prisma with serverless framework aws-nodejs-typescript template

I am building a serverless function using the serverless framework. However im having an issue with running it locally

Error: ENOENT: no such file or directory, open ''/.esbuild/.build/node_modules/.prisma/client/schema.prisma'

prisma/schema.prisma

generator client {
    provider      = "prisma-client-js"
    binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

serverless.ts

package: {
    individually: true,
    patterns: [
        "!node_modules/.prisma/client/libquery_engine-*",
        "node_modules/.prisma/client/libquery_engine-rhel-*",
        "!node_modules/prisma/libquery_engine-*",
        "!node_modules/@prisma/engines/**",
    ],
},

steps:

npx prisma generate && npm install 

sls invoke local -f main

What am i doing wrong here?

note:

  • attempting to follow this example: https://github.com/prisma/prisma-examples/tree/latest/deployment-platforms/aws-lambda

  • i am using the serverless aws-nodejs-typescirpt template which uses serverless-esbuild and not serverless-webpack

like image 601
Kay Avatar asked Oct 31 '25 18:10

Kay


2 Answers

you can solve this by setting the location of Prisma Client. It works for both local and lambda.

prisma/schema.prisma

generator client {
  provider = "prisma-client-js"
  output   = "../src/generated/client"
}
npx prisma generate

serverless.ts

 package: {
    individually: true,
    patterns: [
      "src/generated/client/schema.prisma",
      "!src/generated/client/libquery_engine-*",
      "src/generated/client/libquery_engine-rhel-*",
      "!node_modules/prisma/libquery_engine-*",
      "!node_modules/@prisma/engines/**",
    ],
  },

some function

import { PrismaClient } from "../generated/client";

folder structure

- src
  - functions
  - generated
- serverless.ts
- ...

like image 112
Ken Rhee Avatar answered Nov 03 '25 10:11

Ken Rhee


Looks like you are attempting to import the prisma.schema file from your node_modules file, which is not where it normally goes. Where is your prisma.schema file located relative to the root of your project?

If it's not in ./prisma.schema, you will need to configure its location by using this option:

https://www.prisma.io/docs/concepts/components/prisma-schema#prisma-schema-file-location

like image 31
Shea Hunter Belsky Avatar answered Nov 03 '25 09:11

Shea Hunter Belsky