Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find module error when building docker for NodeJS app

I wrote a DockerFile for a node application. This is the docker file:

FROM node:10.15.0

COPY frontend/  frontend/
WORKDIR frontend/ 
RUN npm install
RUN npm start

When I try to build this Dockerfile, I get this error: ERROR in ./app/main.js Module not found: Error: Can't resolve './ResetPwd' in '/frontend/app'

So I added RUN ls & RUN ls /app in Dockerfile. Both of the files are there! I'm not familiar with NodeJS and it's build process at all. Can anybody help me with this?

Point: I'm not sure if it helps or not, but I'm using Webpack too.

like image 887
taraf Avatar asked Jan 30 '19 19:01

taraf


People also ask

Why can't I find the module'C'in Node JS?

If you are trying to run your Node.js application and you get something like this: Error: Cannot find module 'C:UsersMemy_app.js'. then you are most likely trying to run the wrong file.

How do I install an app in Docker using NPM?

The common way is to create a Dockerfile that is already aware of your application, and make it copy your package.json file and perform an npm install.

What happens to node_modules when I remove a mount from Docker?

As far as I can see you're not doing any installation when starting the container, so the contents of the mount are empty. If you remove that mount, the node_modules path will be populated with what was installed during the docker build (as defined by the Dockerfile) phase.

Why can’t I Run my node app?

If you are trying to run your Node.js application and you get something like this: then you are most likely trying to run the wrong file. It is possible you are missing a dependency that is needed from npm install , but if it says it cannot find the main file you are trying to run, then you are trying to run a file that does not exist.


1 Answers

The problem was that our front-end developer considered that node imports are case insensitive and he was using windows. I tried to run Dockerfile on mac and that's why it couldn't find the modules. Module name was resetPass!

like image 168
taraf Avatar answered Oct 26 '22 09:10

taraf