I can't quite get Prisma working in a container, a...
# orm-help
m
I can't quite get Prisma working in a container, and now I think (hope), I'm at a real general problem, so seeing if anyone has advice. I'll include my Dockerfile. I'm getting this error during spinning up my server:
@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
I think this is happening because the
prisma generate
must be run before
npm install
. Of course, npm install is what installs prisma in the first place. I spun up a new Nest project and tried
npx prisma generate
before installing Prisma. That doesn't throw an error - it results in:
Copy code
Need to install the following packages:
  prisma
Ok to proceed? (y)
So I think maybe my container is ignoring that command prompt (naturally), then trying to run npm install before prisma generate is run. Does this sound like I'm on the right track? The next thing I'm going to try is installing prisma directly, THEN running prisma generate && npm install.
Copy code
FROM node:16.15.1-alpine AS development

WORKDIR /usr/src/app

COPY package*.json ./

COPY . .

RUN npx prisma generate && npm install

RUN npm run build

FROM node:16.15.1-alpine AS production

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/src/app

COPY package*.json ./

RUN npx prisma generate && npm install --production

COPY . .

COPY --from=development /usr/src/app/dist ./dist

CMD ["node", "dist/main"]
l
You need go run
prisma generate
after running any
npm install
☝️ 1
m
... Oh.
Is prisma generate updating the @prisma/client package directly? I thought that npm install had to be run after the generate.
l
https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/generating-prisma-clientgenerating-prisma-client I think prisma generate actually makes the node_module. Since I use the output to have two prisma.schema files that write to different .node_module directories. And then npm install overwrites them
m
Thanks. This is one of those "it works in dev" situations. 😞