4

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:

Kay
  • 17,906
  • 63
  • 162
  • 270
  • It looks like you're calling `npx prisma generate` before `npm install`. Don't you need `prisma` to be installed first through `npm install` before trying to call `prisma` commands? – shmuels Jul 12 '22 at 20:15
  • I had a similar issue and wrote up my solution here: https://stackoverflow.com/questions/73985623/package-files-into-specific-folder-of-application-bundle-when-deploying-to-aws-l – nburk Oct 11 '22 at 09:08

2 Answers2

3

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
- ...

Ken Rhee
  • 31
  • 1
  • 3
1

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

Shea Hunter Belsky
  • 2,815
  • 3
  • 22
  • 31