To fix Cannot find module for a Node app running in a Docker compose environment, we’ve to install the dependencies.
To do this, we write
FROM node:boron
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]
to run npm install
with RUN npm install
to install the dependencies in our Dockerfile.