pnpm isolated monorepo setup
fopefoluwaikufisile
HOBBYOP

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"]
Solved

5 Replies

Can you try running the monorepo from root instead? (apps/api/dist/src/main instead of doing WORKDIR /app/apps/api)


fopefoluwaikufisile
HOBBYOP

a month ago

okay ill try that


fopefoluwaikufisile
HOBBYOP

a month ago

doesnt work


fopefoluwaikufisile
HOBBYOP

a month ago

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


fopefoluwaikufisile
HOBBYOP

a month ago

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


Welcome!

Sign in to your Railway account to join the conversation.

Loading...