Next.js Discord

Discord Forum

Prisma-related Build Error when Deploying with Vercel

Unanswered
RW posted this in #help-forum
Open in Discord
RWOP
I receive the following build error when attempting to deploy my [Next.js app](https://github.com/RW-77/fncomp-analytics-website) with vercel (via git repository):
21:19:42.983 
Module not found: Can't resolve '@/generated/prisma/client'
21:19:42.983 
  1 | import "dotenv/config";
21:19:42.983 
  2 | import { PrismaPg } from '@prisma/adapter-pg'
21:19:42.983 
> 3 | import { PrismaClient } from '@/generated/prisma/client'
21:19:42.984 
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21:19:42.984 
  4 |
21:19:42.984 
  5 | const connectionString = `${process.env.DATABASE_URL}`
21:19:42.984 
  6 |
21:19:42.984 
21:19:42.984 
Import map: aliased to relative './generated/prisma/client' inside of [project]/
21:19:42.984 
21:19:42.984 
21:19:42.984 
Import trace:
21:19:42.984 
  Server Component:
21:19:42.984 
    ./lib/prisma.ts
21:19:42.984 
    ./app/tournaments/page.tsx
21:19:42.984 
21:19:42.984 
https://nextjs.org/docs/messages/module-not-found
21:19:42.984 
21:19:42.984 
21:19:42.984 
    at <unknown> (./lib/prisma.ts:3:1)
21:19:42.984 
    at <unknown> (https://nextjs.org/docs/messages/module-not-found)
21:19:43.039 
 ELIFECYCLE  Command failed with exit code 1.
21:19:43.060 
Error: Command "pnpm run build" exited with 1

It seems like Prisma is generating the client after Next.js tries to build, but my package.json includes a build script prisma generate && next build, so I'm not sure what's going on.
{
  "name": "fortnite-stats-website",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "prisma generate && next build",
    "start": "next start",
    "lint": "eslint",
    "postinstall": "prisma generate"
  },
  "dependencies": {
    // dependencies
  },
  "devDependencies": {
    // devDependencies
  }
}

If needed, the repository can be found [here](https://github.com/RW-77/fncomp-analytics-website)

11 Replies

Cape lion
hi did you check your build and deployment settings?
this is in vercel's settings
Cape lion
if you run the build script in your local env do you get the same error?
@Cape lion hi did you check your build and deployment settings?
RWOP
does the package.json not take care of that already?
RWOP
I guess my main question is whether I need to first host my DB before trying to deploy with vercel.

Running locally, I just have an .env file with my localhost DB url (which I'm don't think is even part of the repo), and I haven't taken any additional steps between that and deploying the whole site.
Cape lion
yes you'll need to host your db, and the build settings i linked to override the package.json (this should override the vercel.json actually)
RWOP
I hosted my DB with neon and created an environment variable in the vercel project, but the link you gave me is invalid
It might be helpful to know that each time I try to deploy, I receive a warning which I think prevents prisma generate from being executed:
╭ Warning ─────────────────────────────────────────────────────────────────────╮
│                                                                              │
│   Ignored build scripts: @prisma/engines@7.1.0, esbuild@0.27.1,              │
│   prisma@7.1.0, sharp@0.34.5, unrs-resolver@1.11.1.                          │
│   Run "pnpm approve-builds" to pick which dependencies should be allowed     │
│   to run scripts.                                                            │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
RWOP
I didn't change a thing and it randomly deployed successfully for the first time
Long-horned bees
If it happens again please ping me