Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serverless error: "PrismaClientInitializationError: Prisma Client could not find its schema.prisma" #27

Open
ssalihu opened this issue Jul 8, 2023 · 3 comments

Comments

@ssalihu
Copy link

ssalihu commented Jul 8, 2023

Hello! I am facing serverless invocation issue. Appreciate any help!

Followed this link for deployment and getting the below error.

Error: PrismaClientInitializationError: Prisma Client could not find its schema.prisma. This is likely caused by a bundling step, which leads to schema.prisma not being copied near the resulting bundle. We would appreciate if you could take the time to share some information with us

Zip file contents snippet

Archive:  .serverless/dev-project.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      411  01-01-1980 00:00   prisma/schema.prisma

Code to initialize the client as below. This uses the datasources parameter.


async function buildDbUrl() {
    const DB_PASSWORD = await generateDBAuthToken()
    const url = `postgresql://${DB_CONSTANTS.USER_NAME}:${DB_PASSWORD}@${DB_CONSTANTS.HOST}:${DB_CONSTANTS.PORT}/${DB_CONSTANTS.NAME}?schema=${DB_CONSTANTS.SCHEMA_NAME}`;
    
    return url;
}

const getPrismaClient = async () => {
    const dbUrl = await buildDbUrl();
    return new PrismaClient({
        datasources: {
            db: {
                url: dbUrl,
            }
        },
    });
};

I am using webpack in my project. I am able to get it to work if i am not using webpack.

Here is the configuration that does not work.

plugins:

  • serverless-webpack
  • serverless-webpack-prisma

custom:
webpack:
includeModules: true
Here is the output from sls package

assets by path src/api/trade/*.js 19.5 MiB
    asset src/api/detailReport.js 9.75 MiB [emitted] [minimized] (name: src/api/detailReport) 2 related assets
    asset src/api/dailyTradeReport.js 9.75 MiB [emitted] [minimized] (name: src/api/dailyTradeReport) 2 related assets

  orphan modules 773 KiB [orphan] 542 modules
  runtime modules 4.58 KiB 20 modules
  modules by path ./node_modules/aws-sdk/ 9.17 MiB 1291 modules
  modules by path ./node_modules/xmlbuilder/lib/*.js 127 KiB 33 modules
  modules by path ./src/ 56.5 KiB 14 modules
  modules by path ./node_modules/fast-xml-parser/src/ 60.6 KiB 11 modules
  modules by path ./node_modules/@aws-crypto/ 19.4 KiB 8 modules
  modules by path ./node_modules/xml2js/lib/*.js 20.7 KiB 6 modules
  modules by path ./node_modules/uuid/dist/esm-node/*.js 9.82 KiB 5 modules
  modules by path ./node_modules/xlsx/ 1.42 MiB 3 modules
  modules by path ./node_modules/@prisma/client/ 211 KiB 2 modules
  modules by path ./node_modules/@aws-sdk/ 370 KiB 2 modules
  + 25 modules
  
  WARNING in ./node_modules/@aws-sdk/util-user-agent-node/dist-es/is-crt-available.js 3:78-96
  Module not found: Error: Can't resolve 'aws-crt' in '/Users/e128270/Documents/swa-aws/stars/code/stars-trade-reports/node_modules/@aws-sdk/util-user-agent-node/dist-es'
   @ ./node_modules/@aws-sdk/util-user-agent-node/dist-es/index.js 4:0-52 15:25-39
   @ ./node_modules/@aws-sdk/client-sts/dist-es/runtimeConfig.js 4:0-65 29:12-28
   @ ./node_modules/@aws-sdk/client-sts/dist-es/STSClient.js 12:0-73 16:26-44
   @ ./node_modules/@aws-sdk/client-sts/dist-es/index.js 1:0-28 1:0-28
   @ ./node_modules/@aws-sdk/credential-providers/dist-es/fromIni.js 1:0-98 5:37-58 6:67-103
   @ ./node_modules/@aws-sdk/credential-providers/dist-es/index.js 5:0-26 5:0-26
   @ ./node_modules/@aws-sdk/rds-signer/dist-es/runtimeConfig.js 1:0-70 9:44-65
   @ ./node_modules/@aws-sdk/rds-signer/dist-es/Signer.js 4:0-73 9:37-55
   @ ./node_modules/@aws-sdk/rds-signer/dist-es/index.js 1:0-25 1:0-25
   @ ./src/util/awsUtil.js
   @ ./src/util/prismaUtil.js 2:32-52
   @ ./src/util/DBHelper.js 1:28-57
   @ ./src/api/generateReport.js 6:41-85
  
  1 warning has detailed information that is not shown.
  Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
  
  webpack 5.75.0 compiled with 1 warning in 17045 ms
No external modules needed
Install prisma devDependencies for generate
Copy prisma schema for service...
Generate prisma client for service...
Remove prisma devDependencies

✔ Service packaged (23s)
@archy-bold
Copy link

I have this issue too.

@archy-bold
Copy link

Looks like this is affecting people outside of this plugin. Prisma have an issue tracking it: prisma/prisma#19351

There's a suggestion that the prisma directory be manually copied over, but I assume this plugin does that.

@adamjq
Copy link

adamjq commented Jul 16, 2023

I ran into a similar issue - not with the serverless-webpack plugin but with my own webpack config. I solved it and documented the solution here in case this helps: prisma/prisma#19351 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants