When I try to run a docker container from an image I just built using "docker run" Node.js can't find express even though it is installed and the Dockerfile compiles fine.
Here is the output
> dev
> nodemon
[nodemon] 2.0.22
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
node:internal/modules/cjs/loader:1063
throw err;
^
Error: Cannot find module 'express'
Require stack:
- /app/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1060:15)
at Module._load (node:internal/modules/cjs/loader:905:27)
at Module.require (node:internal/modules/cjs/loader:1127:19)
at require (node:internal/modules/helpers:112:18)
at Object.<anonymous> (/app/index.js:3:17)
at Module._compile (node:internal/modules/cjs/loader:1246:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
at Module.load (node:internal/modules/cjs/loader:1103:32)
at Module._load (node:internal/modules/cjs/loader:942:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/index.js' ]
}
Node.js v19.5.0
[nodemon] app crashed - waiting for file changes before starting...
And Here is my Dockerfile
FROM node:alpine
WORKDIR "/app"
COPY ./package.json ./
RUN rm -rf node_modules
RUN rm -f package-lock.json
RUN npm cache clean --force
RUN npm init -y
RUN npm install -g [email protected]
RUN npm install -g express --save
RUN npm install -g nodemon --save
RUN npm install -g validator --save
RUN npm install -g is-empty --save
COPY . .
CMD ["npm", "run", "dev"]