Kevin Seab
Kevin Seab

Reputation: 21

Build Nest.js in docker got a Prisma erorr

I am building an application in nest.js ,then I want to dockerize it by using docker, this is my docker file:

FROM node:14 AS builder

# Create app directory
WORKDIR /app

# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
COPY prisma ./prisma/

# Install app dependencies
RUN npm install

COPY . .

RUN npm run build

FROM node:14

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/dist ./dist

EXPOSE 3000
CMD [ "npm", "run", "start:prod" ]

Then when I run :

docker build -t medicine-api .

I got this erorr from prisma

Module '"@prisma/client"' has no exported member 'User'.

3 import { User } from '@prisma/client';

and this is my prisma.schema file

/ This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

generator prismaClassGenerator {
  provider = "prisma-class-generator"
  dryRun   = false
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id               Int                @id @default(autoincrement())
  phoneNumber      String             @unique
  lastName         String
  firstName        String
  role             Role
  bio              String?
  certificate      String?
  pic              String?
  verified         Boolean            @default(false)
  medicine         Medicine[]
  pharmacyMedicine PharmacyMedicine[]
  medicineCategory MedicineCategory[]
  pharmacyPackage  PharmacyPackage[]
  pharmacistOrder  Order[]            @relation("pharmacistOrder")
  userOrder        Order[]            @relation("userOrder")
}

I try to fix this by searching through difference resource and website, then they recommend me to put npx prisma generate in my dockefil. But still I get another erorr here:

Error: Generator at prisma-class-generator could not start:

/bin/sh: 1: prisma-class-generator: not found

If you have any solutions , I am really happy to try. Thanks in advance.

Upvotes: 2

Views: 1854

Answers (1)

Joud Awad
Joud Awad

Reputation: 23

You have to generate the prisma client by running the command

yarn prisma generate

this should come before the step of coping the prisma folder so I would suggest to change the dockerFile to be

FROM node:14 AS builder

# Create app directory
WORKDIR /app

# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./

# Install app dependencies
RUN npm install

COPY . .

RUN yarn prisma generate
COPY prisma ./prisma/


RUN npm run build

FROM node:14

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/dist ./dist

EXPOSE 3000
CMD [ "npm", "run", "start:prod" ]

the prisma generate step will make sure you will have the prisma client in your node_modules so that it can be used to migrate the prisma models

Upvotes: 2

Related Questions