#Problems with finding nest after copying /node_modules in docker stag

3 messages · Page 1 of 1 (latest)

unique grove
#

Getting an error on 'npm run start' line wherein docker cannot find nest (seeing issue in azure pipeline docker build step)

sh: nest: not found
The command '/bin/sh -c npm run build' returned a non-zero code: 127
##[error]The command '/bin/sh -c npm run build' returned a non-zero code: 127
##[error]The process '/usr/bin/docker' failed with exit code 127

Here is my docker file

FROM node:16.13.0-alpine3.14 AS development
ENV NODE_ENV=production
WORKDIR /usr/src/app

COPY --chown=node:node package*.json ./

RUN npm install

COPY --chown=node:node . .

FROM node:16.13.0-alpine3.14 AS build
ENV NODE_ENV=production
WORKDIR /usr/src/app

COPY --chown=node:node package*.json ./
COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules
COPY --chown=node:node . .

# Run the build command which creates the production bundle
RUN npm run build

ARG BuildId
LABEL test=${BuildId}
RUN npm run test:ci

RUN npm ci --only=production && npm cache clean --force

FROM node:16.13.0-alpine3.14 AS production
ENV NODE_ENV=production
WORKDIR /usr/src/app
USER node

COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
COPY --chown=node:node --from=build /usr/src/app/dist ./dist

CMD [ "node", "dist/main.js" ]

Things I've tried:

  1. confirming the docker file works fine locally when run with docker build --no-cache
  2. run docker exec --it on the intermediary stages and confirmed that usr/src/app/node_modules/.bin/nest exists
  3. Tried running with an adding path ENV PATH="./node_modules/.bin:$PATH"
  4. Tried adding "RUN npm i -g @nestjs/cli" before the npm run build command

I'm seeing the errors in azure pipeline docker build step.
Please let me know if you see I am doing something wrong or have any suggestions for ways to further debug this issue.

unique grove
#

I found the problem. If anyone runs into a similar one in the future 😄
If you set NODE_ENV=production, it will only download production dependencies, even if running npm install

craggy ingot
#

npm ci is a thing too fyi