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.

serverless nextjs config needs official support/documentation

See original GitHub issue

Bug description

Prisma doesn’t work out of the box with Nextjs and AWS serverless framework. https://github.com/prisma/prisma/issues/6032

@millsp proposed a solution inside the serverless config file: https://github.com/millsp/prisma-serverless-nextjs

# serverless.yml
    build:
      postBuildCommands:
        - PDIR=node_modules/.prisma/client/;
          LDIR=.serverless_nextjs/api-lambda/;
          if [ "$(ls -A $LDIR)" ]; then
            mkdir -p $LDIR$PDIR;
            cp "$PDIR"query-engine-rhel-* $LDIR$PDIR;
            cp "$PDIR"schema.prisma $LDIR$PDIR;
          fi;
        - PDIR=node_modules/.prisma/client/;
          LDIR=.serverless_nextjs/default-lambda/;
            if [ "$(ls -A $LDIR)" ]; then
              mkdir -p $LDIR$PDIR;
              cp "$PDIR"query-engine-rhel-* $LDIR$PDIR;
              cp "$PDIR"schema.prisma $LDIR$PDIR;
          fi;

The solution needs official support in prisma generate or a reference in the prisma docs.

I propose a prisma config like serverless: true that runs the above script automatically.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
amitleuva1987commented, Jul 15, 2022

this is issue is solved. It doesn’t require these much of of code below postBuildCommands. It just required two lines of code in latest versions (next > 12 and prisma >= 4).

inputs:
     useServerlessTraceTarget: true

for older version (next 10, 11) (prisma 3.15)

you need to add below line in your next.config.js

target: 'experimental-serverless-trace'

reference issue

0reactions
amitleuva1987commented, Jul 12, 2022

@jeremygottfried , I opened a new issue with prisma. But, I may probably solve it myself and post the solution.

But, your raised issue was very valid that it should have a proper document. Such fixes is not a good standard for using any plugin or library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blog - Next.js 8
Next.js 8 introduces Serverless Mode, smaller bundles, performance improvements, and more.
Read more >
Serverless Next.js Component - Serverless Framework: Plugins
A zero configuration Next.js 10/11 serverless component for AWS ... The component takes care of all the routing for you so there is...
Read more >
Inputs - Serverless Nextjs
Name Type Default Value domain Array null bucketName string null bucketRegion string us‑east‑1
Read more >
How Tencent Scales to Millions with Serverless Next.js
Combining the Serverless Services and Next.js Framework, Tencent Online Education team scales to millions and also saving costs by 90%.
Read more >
serverless-nextjs-plugin - npm package - Snyk
npm install --save-dev serverless-nextjs-plugin. Out of the box, the plugin won't require any configuration. If you need to override any defaults check this ......
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