a month ago
pnpm monorepo + Turborepo deploying NestJS on Railway. Build succeeds, dist folder exists, but getting Cannot find module 'express' at runtime. ls node_modules | grep express && node dist/src/main works but node dist/src/main alone fails. NODE_PATH fix didn't work.
Here's my docker file
FROM node:22-alpine
RUN npm install -g pnpm
WORKDIR /app
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY apps/api/package.json ./apps/api/
COPY packages/ ./packages/
COPY apps/api ./apps/api
RUN pnpm install --frozen-lockfile
RUN pnpm --filter api prisma:generate
RUN pnpm --filter api build
ENV NODE_PATH=/app/node_modules
WORKDIR /app/apps/api
EXPOSE 3001
CMD ["node", "dist/src/main"]5 Replies
a month ago
Can you try running the monorepo from root instead? (apps/api/dist/src/main instead of doing WORKDIR /app/apps/api)
i fixed it, i was importing request and response types from express in the app, but just imported them as types instead and it worked
for context changed
import express from express
express.Request
to
import type { Request as ExpressRequest, Response as ExpressResponse, } from 'express';
Status changed to Solved 0x5b62656e5d • about 1 month ago