question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bundling prisma2 with the plugin

See original GitHub issue

Hi,

I’m having trouble initializing prisma when using the serverless-bundle plugin

Prisma needs to run a script “prisma generate” and uses a schema.prisma file (that i need to copy into the webpack bundle process) in order to make the client to access the database. I have added this part in the custom options of the plugin like so:

custom:
  bundle:
    copyFiles:
      - from: "prisma/schema.prisma"
        to: "./"
    packagerOptions:
      scripts:
        - prisma generate

But then when I run serverless offline and i execute an api i get this error: Failed to execute scheduled function: [hello] Error: Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again

It looks as though the script is not being run. Is there a way to see logs and see what is happening during the bundling process? Maybe the script is failing and it would be easier if i could see the output of the script.

Node Version : 14.0.0 NPM Version: 6.9.0 Serverless Bundle version: 3.2.1

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
ADrejtacommented, Apr 5, 2021

I came back to this and tried this setup with these configs: Node version : 14.0.0 serverless: 2.33.1 serverless-bundle: 3.0.0

Looks like prisma has to be added in to the externals sections in order to work properly

custom:
   bundle:
      externals:
         - "@prisma/client"
      copyFiles:
         - from: "prisma/schema.prisma"
           to: "./"
      packagerOptions:
         scripts:
            - prisma generate

I think adding prisma to the default list of externals would be a good idea in this case. This should probably be closed now since adding prisma to the externals options does do the trick, but i will leave it open in case it is used as a reference to add prisma to the default externals list or something.

0reactions
jayaircommented, Jan 3, 2021

We are currently relying on serverless-webpack for the custom scripts: https://github.com/serverless-heaven/serverless-webpack#custom-scripts

Does anybody want to take a look why it’s not being invoked?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module bundlers (Reference) - Prisma
Module bundlers bundle JavaScript modules into a single JavaScript file. ... To do so, you can use plugins that let you copy over...
Read more >
Deploying Prisma with AWS Lambda and Webpack #2303
I have spent the better part of a weekend trying in earnest to deploy a simple rest api using prisma2, unsuccessfully for one...
Read more >
Lets take Prisma 2 for a test drive on AWS Lambda ... - ITNEXT
Now you need to add the copy-webpack-plugin that will give Webpack access to the binary file that is needed once our code is...
Read more >
Getting Started with the Prisma Framework (formerly Prisma 2 ...
Start a new Prisma 2 project by using the npx command as follows: $ npx prisma2 init server ... We also add nexusPrismaPlugin...
Read more >
Building Dad Jokes using The Prisma Framework (formerly ...
The Prisma Framework (formerly known as Prisma 2) is a complete rewrite of ... With The Prisma Framework, the query engine is now...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found