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.

@sls-next/serverless-components 3.4.x break deployment with Prisma ORM (schema.prisma not found)

See original GitHub issue

Issue Summary

Prior to the 3.4.x releases of @sls-next/serverless-components, I had a working serverless build that included Prisma ORM.

The working build required me to use the postBuildCommands property to copy the schema.prisma file and query engine (query-engine-rhel-*) to the appropriate folders to make the deployment work on AWS.

Now, when deploying the app, I get an error stating that .next/serverless/chunks/schema.prisma can’t be found.

Error: ENOENT: no such file or directory, open '/Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/chunks/schema.prisma'

I also get a warning, but I don’t think it’s actually causing problems.

../../node_modules/.bin/next build
(node:29546) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API

The postBuildCommands that made the build work before were…

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

Actual behavior

When I run the following command, I get an error stating that schema.prisma cannot be found.

npx -w apps/client serverless

Expected behavior

When I run the following command, the app should be deployed to AWS as before.

npx -w apps/client serverless

Steps to reproduce

Use NPM v7 for workspace support.

# ~/git/example
node -v
v14.17.4

npm -v
7.20.5

Checkout the code from

git clone git@github.com:baronnoraz/nextjs-prisma-monorepo-serverless-deployment-issue.git example

A more detailed README.md is located in the root of the project, but these are the minimal steps.

Configure AWS credentials in example/apps/client/.env.

Optionally (if you want to run the application), create an AWS RDS instance and configure the DATABASE_URL in example/apps/client/.env and example/db/prisma/.env.

Install dependencies

# example/
npm install

Generate the schema.prisma file and Prisma Query engine

# example/
npx -w db/prisma prisma generate

Deploy the app

# example/
npx -w apps/client serverless

Screenshots/Code/Configuration/Logs

The error that I get is…

  17s › exampleApp › Error: Command failed with exit code 1: ../../node_modules/.bin/next build
(node:32204) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API
(Use `node --trace-deprecation ...` to show where the warning was created)
warn  - Compiled with warnings

../../node_modules/next/dist/server/load-components.js
Critical dependency: the request of a dependency is an expression

../../node_modules/next/dist/server/load-components.js
Critical dependency: the request of a dependency is an expression

../../node_modules/next/dist/server/load-components.js
Critical dependency: the request of a dependency is an expression

../../node_modules/next/dist/server/require.js
Critical dependency: the request of a dependency is an expression

../../node_modules/next/dist/server/require.js
Critical dependency: the request of a dependency is an expression

../../node_modules/next/dist/server/require.js
Critical dependency: the request of a dependency is an expression


> Build error occurred
Error: ENOENT: no such file or directory, open '/Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/chunks/schema.prisma'
    at Object.openSync (fs.js:498:3)
    at Object.readFileSync (fs.js:394:35)
    at new LibraryEngine (/Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/chunks/569.js:25128:42)
    at PrismaClient.getEngine (/Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/chunks/569.js:37747:16)
    at new PrismaClient (/Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/chunks/569.js:37716:29)
    at Module.1074 (/Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/pages/index.js:26:16)
    at __webpack_require__ (/Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/pages/index.js:465:43)
    at Module.6884 (/Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/pages/index.js:154:23)
    at __webpack_require__ (/Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/pages/index.js:465:43)
    at /Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/pages/index.js:485:96 {
  type: 'Error',
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.next/serverless/chunks/schema.prisma',
  clientVersion: '3.1.1'
}
info  - Loaded env from /Users/nbuckner/git/nextjs-prisma-monorepo-serverless-deployment-issue/apps/client/.env
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
info  - Checking validity of types...
info  - Creating an optimized production build...
info  - Collecting page data...

Versions

  • OS/Environment: macOS Catalina 10.15.7
  • Node v14.17.4
  • NPM v7.20.5
  • @sls-next/serverless-component version: 3.4.0-alpha.11
  • Next.js version: 11.1.2
  • @prisma/client version: 3.1.1
  • prisma version: 3.1.1
  • serverless version: 2.60.0

Additional context

This was working prior to upgrading to @sls-next/serverless-component 3.4.x. I went down this road, because I was running into some issues with next-auth and the @next-auth/prisma-adapter. I got everything to work together locally after all of the upgrades, but when I went to deploy the app to AWS it failed.

I started the example repo from the ground up to try and determine why the deployment no longer worked. It seems that something is different in the file resolution of schema.prisma, but I’ve been unable to figure out what.

To be fair there were issues in the previous version, but I could use the postBuildCommands to copy the schema.prisma file to where I needed it. The deployment appears to fail earlier in the process now.

Checklist

  • You have reviewed the README and FAQs, which answers several common questions.
  • You have reviewed our DEBUGGING wiki and have tried your best to include complete information and reproduction steps (including your configuration) as is possible.
  • You have first tried using the most recent latest or alpha @sls-next/serverless-component release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
MGoughcommented, Nov 19, 2021

Looks like we have a similar project structure! Yarn workspaces by any chance?

We had the same error, what’s odd though is that we were using @sls-next/serverless-components 3.1.0 and started seeing this once we added prisma calls to our getServerSideProps. It didn’t seem to be linked to upgrading any versions (serverless-components, next, prisma).

We saw it on Prisma 3.2.1 and 3.5.0. Serverless components version 3.1.0 and 3.6.0. It happened locally and on github actions.

It seems like it’s primarily an issue between next and prisma, as we were seeing it locally if we ran next build with target: serverless, so potentially not actually related to serverless-next.js

1reaction
baronnorazcommented, Sep 30, 2021

Ok, so this isn’t the “fix”, but I got it to work. Hopefully, it will help others.

I installed the copy-webpack-plugin and modified my next.config.js to

const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  reactStrictMode: true,
  webpack: (config, {isServer}) => {
    if (isServer) {
      config.externals.push('_http_common');
    }
    config.plugins.push(
      new CopyWebpackPlugin({
        patterns: [{
          from: '../../node_modules/.prisma/client/schema.prisma',
          to: './'
        }, {
          from: '../../node_modules/.prisma/client/libquery_engine-rhel-openssl-1.0.x.so.node',
          to: './'
        }]
      })
    )
    return config;
  }
};

You’ll probably have to adjust those paths for your needs, because that’s specific to my monorepo structure, but it makes it work for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma schema (Reference)
The Prisma schema is the main configuration file when using Prisma. It is typically called schema.prisma and contains your database connection and data ......
Read more >
Upgrade to Prisma 3
Prisma 3 introduces a number of breaking changes if you are upgrading from an earlier version (any 2.x version), therefore, it is important...
Read more >
Upgrade to Prisma 4
Prisma 4 introduces a number of breaking changes when you upgrade from an earlier Prisma ... Review changes of the Prisma schema and...
Read more >
Migration troubleshooting in development - Prisma
Fixing schema drift in a development environment · Reset your database: $npx prisma migrate reset · Replicate the changes in the Prisma schema...
Read more >
Prisma schema API (Reference)
The field is named relationMode in versions 4.5.0 and later, and was previously named referentialIntegrity . extensions, No, List of strings (PostgreSQL ...
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