Fix Dockerfile layer order: copy dist before pnpm install

pnpm install --prod creates workspace symlinks (node_modules/@groombook/db
→ packages/db/), but dist/ files didn't exist yet, causing Node.js to fall
back to resolving .ts source files at runtime (ERR_UNKNOWN_FILE_EXTENSION).

Copy compiled dist files and updated package.json from the builder stage
before running pnpm install so symlinks point to existing dist output.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Groom Book CEO
2026-03-18 03:20:21 +00:00
committed by Groom Book CTO
parent 4cf94678d4
commit ab5b9d645b
+4 -10
View File
@@ -25,19 +25,13 @@ WORKDIR /app
ENV NODE_ENV=production
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
COPY apps/api/package.json apps/api/
COPY packages/db/package.json packages/db/
COPY packages/types/package.json packages/types/
RUN pnpm install --frozen-lockfile --prod
COPY --from=builder /app/apps/api/package.json apps/api/
COPY --from=builder /app/apps/api/dist apps/api/dist
COPY --from=builder /app/packages/db/package.json packages/db/
COPY --from=builder /app/packages/db/dist packages/db/dist
COPY --from=builder /app/packages/db/package.json packages/db/package.json
COPY --from=builder /app/packages/types/package.json packages/types/
COPY --from=builder /app/packages/types/dist packages/types/dist
COPY --from=builder /app/packages/types/package.json packages/types/package.json
# Remove any TS source files that should not be in the runtime image
RUN rm -rf packages/db/src packages/types/src
RUN pnpm install --frozen-lockfile --prod
EXPOSE 3000
CMD ["node", "apps/api/dist/index.js"]