build - Getting Error on building docker image for nestjs microservice, but works fine in nest building in local machine - Stack

admin2025-04-16  2

Getting this type of errors on docker build for Step 5/10 : RUN npm run build Cannot find module '@app/common/constants' or its corresponding type declarations import { jwtConstants } from '@app/common/constants'; but the nest build command works fine on local machine.

Dockerfile

FROM node:18-alpine as build

WORKDIR /usr/share/app-gateway

COPY . ./

RUN npm ci --omit=dev

RUN npm run build

FROM node:18-alpine

WORKDIR /usr/share/app-gateway

COPY --from=build /usr/share/app-gateway .

EXPOSE 3000
su
CMD ["node", "apps/app-gateway/src/main.js"]`

how the nestjs build correclty in local but not in docker?

I want to make services build independently and should be able to deploy , node /dist/path_to_main/main.js was running fine in local machine but the nest build is failing in dockerfile.

转载请注明原文地址:http://www.anycun.com/QandA/1744762137a87256.html