Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

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

Open
@baronnoraz

Description

@baronnoraz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions