Error on docker build of React app: Cannot resolve module
I created an app using the create-react-app which works fine.
When I try to docker build with the following Dockerfile:
FROM node:7.7.4 ADD package.json /tmp/package.json ADD public /tmp/public ADD src /tmp/src ADD .env /tmp/.env RUN cd /tmp && \ npm install && \ npm run build <-- failing on this step
I am getting the following error:
Module not found: Error: Cannot resolve module 'moment' in /tmp/src
and the build naturally fails.
I have tried adding the moment module in my package.json (
npm install moment --save) but the error remained.
What am I missing here?
One Solution collect form web for “Error on docker build of React app: Cannot resolve module”
After some fiddling around in the containers, I discovered that the node_module folder does not pass with all it’s dependencies in the docker container. So there are two ways to fix this:
- The economic one:
add your dependencies in the package.json file and on the
npm installtime everything gets assorted. (That fixed my problem!)
If you have a local build which you don’t share over Git and you are not using a .dockerignore file as I did, you can simply add everything from your development folder to the container as follows:
ADD package.json /tmp/package.json ADD . .
replacing the other ADD lines I had in there.