Score:0

Docker container can't find express even though it is installed and the Dockerfile compiles fine

cn flag

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"]
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.