That's what I did in package.json file (It was a deploy a Next app on Versel) I just added generate command to the build script:
"scripts": {
"dev": "next dev",
"build": "prisma generate && next build",
"start": "next start",
"lint": "next lint"
},
Not sure if it is a correct way, though..
Answer from maxuapro on Stack OverflowThat's what I did in package.json file (It was a deploy a Next app on Versel) I just added generate command to the build script:
"scripts": {
"dev": "next dev",
"build": "prisma generate && next build",
"start": "next start",
"lint": "next lint"
},
Not sure if it is a correct way, though..
There's no need to run the prisma generate command that is executed on installation of the @prisma/client.
EDIT: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/generating-prisma-client
node.js - @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again - Stack Overflow
Nextjs vercel deployement prisma issue
Has anyone deployed Prisma recently with NextJS 13?
Question: Override default postinstall script - for custom path
Just remove the following line from the schema.prisma file:
output = "../generated/prisma"
and execute:
npx prisma generate
I know that this has been marked as solved, but I just wanted to share my setup for anyone interested.
Dockerfile
# Build image
FROM node:16.13-alpine as builder
WORKDIR /app
# Not sure if you will need this
# RUN apk add --update openssl
COPY package*.json ./
RUN npm ci --quiet
COPY ./prisma prisma
COPY ./src src
RUN npm run build
# Production image
FROM node:16.13-alpine
WORKDIR /app
ENV NODE_ENV production
COPY package*.json ./
RUN npm ci --only=production --quiet
COPY --chown=node:node --from=builder /app/prisma /app/prisma
COPY --chown=node:node --from=builder /app/src /app/src
USER node
EXPOSE 8080
CMD ["node", "src/index.js"]
package.json
{
"name": "example",
"description": "",
"version": "0.1.0",
"scripts": {
"generate": "npx prisma generate",
"deploy": "npx prisma migrate deploy",
"dev": "npm run generate && nodemon --watch \"src/**\" --ext \"js,json\" --exec \"node src/index.js\"",
"build": "npm run generate",
"start": "npm run build && node build/index.js"
},
"prisma": {
"schema": "prisma/schema.prisma"
},
"dependencies": {
"@prisma/client": "^3.6.0"
},
"devDependencies": {
"@tsconfig/node16": "^1.0.2",
"@types/node": "^16.11.12",
"nodemon": "^2.0.15",
"prisma": "^3.6.0"
}
}
I run this in Kubernetes. To make things smooth with database and migrations I run an initContainer that runs the prisma migrate deploy.
apiVersion: apps/v1
kind: Deployment
metadata:
name: EXAMPLE
spec:
replicas: 1
selector:
matchLabels:
app: EXAMPLE
strategy:
rollingUpdate:
maxSurge: 100%
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
labels:
app: EXAMPLE
spec:
containers:
image: DOCKER_IMAGE
imagePullPolicy: IfNotPresent
name: SERVICE_NAME
ports:
- containerPort: 8080
name: http
protocol: TCP
initContainers:
- command:
- npm
- run
- deploy
image: DOCKER_IMAGE
imagePullPolicy: IfNotPresent
name: database-migrate-deploy
(This is a live service I just copied and stripped away anything non essential)
I hope this could be of use to someone
Can anyone check on this issue https://github.com/prisma/prisma/discussions/23741
I used Vercel for deployment and tried everything modifying build script to include "prisma generate" command, generating prisma in a separate folder and uploading that and postinstall script but still on every single deployment I get Prisma Client Initiation error. And all solutions work fine on my local. If anyone had experienced the same would appreciate if you have any tips on how to resolve this.
PS: I did try adding "prisma generate" in postinstall script.
Have used and deployed projects with Prisma before successfully so not sure what's different this time, also tried clearing cache multiple times and creating a new project.