I've set up a docker configuration to run my React app, but when starting the container, I encounter the following error:
frontend-1 | failed to load config from /app/vite.config.ts
frontend-1 | error when starting dev server:
frontend-1 | Error: Cannot find module @rollup/rollup-linux-x64-musl. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.
frontend-1 | at requireWithFriendlyError (/app/node_modules/rollup/dist/native.js:59:9)
frontend-1 | at Object.<anonymous> (/app/node_modules/rollup/dist/native.js:68:76)
frontend-1 | at Module._compile (node:internal/modules/cjs/loader:1368:14)
frontend-1 | at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
frontend-1 | at Module.load (node:internal/modules/cjs/loader:1205:32)
frontend-1 | at Module._load (node:internal/modules/cjs/loader:1021:12)
frontend-1 | at cjsLoader (node:internal/modules/esm/translators:366:17)
frontend-1 | at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:315:7)
frontend-1 | at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
frontend-1 | at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
frontend-1 exited with code 1
The React app functions correctly when run locally outside of Docker, and it also operates as expected when launched using the docker run command. But, when attempting to start the app with docker-compose up, it fails to function. I was unable to find a solution online.
Dockerfile:
FROM node:21-alpine
RUN npm install -g vite
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 5173
CMD ["vite", "--host", "0.0.0.0"]
docker-compose.yml:
version: '3.8'
services:
reactApp:
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/app
ports:
- "9000:5173"
.dockerignore:
node_modules
package-lock.json
volumes:
block is overwriting the code andnode_modules
tree in your image with content from your host. Does deleting that block help? – Rhodesia