#Error: Cannot find module '/app/astro' in Docker container

4 messages · Page 1 of 1 (latest)

brave nexus
#

Hi, I'm doing a project with Astro for frontend and Symfony for backend. It is literally my first project using these technologies from the beginning to the ending, so I probably made a lot of mistakes. The thing is that I have the Dockerfiles done for either Astro and Symfony, but when running the following command: "docker compose up --build" it throws an error when reaching the frontend container: "Error: Cannot find module '/app/astro'". First, I'll show the Astro Dockerfile, the docker-composer.yaml and the package.json, then the error log.

#

Astro Dockerfile: FROM node:lts AS runtime

WORKDIR /app

Copy package.json and package-lock.json (if available)

COPY package*.json ./

Install dependencies

RUN npm install

Copy the rest of your project files

COPY . .

Build the Astro project

RUN npm run build

ENV HOST=0.0.0.0
ENV PORT=4321

EXPOSE 4321

Use the start script instead of dev for production

CMD ["npm", "start"]

#

docker-composer.yaml: services:

Servicio para el frontend (Astro)

frontend:
command: astro dev --host 0.0.0.0
build:
context: ./LearnWebAstro # Ubicación del Dockerfile de frontend
ports:
- "4321:4321" # Mapeamos el puerto 4321 del contenedor al 4321 en tu máquina local
depends_on:
- backend # Este servicio depende del backend (Symfony)
environment:
- API_URL=http://backend:8000 # Usamos el nombre del servicio 'backend' para la comunicación interna en Docker
volumes:
- ./LearnWebAstro:/app # Montamos el código local para desarrollo
- /app/node_modules # Esto asegura que node_modules no se sobrescriba
networks:
- app-network # Aseguramos que ambos contenedores estén en la misma red

Servicio para el backend (Symfony)

backend:
build:
context: ./LearnWebApi # Ubicación del Dockerfile de backend
ports:
- "8000:8000" # Mapeamos el puerto 8000 del contenedor al 8000 en tu máquina local
volumes:
- ./LearnWebApi:/var/www/symfony # Esto permite que los cambios en el código se reflejen en el contenedor
environment:
- DATABASE_URL=mysql://root:root@db:3306/LearnWeb # Usamos el nombre del servicio 'db' para la base de datos en Docker
networks:
- app-network # Aseguramos que ambos contenedores estén en la misma red

Servicio para la base de datos (MySQL)

db:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: LearnWeb
ports:
- "3307:3306" # O cualquier otro puerto que necesites
networks:
- app-network # Conectamos la base de datos a la misma red

networks:
app-network:
driver: bridge # Usamos la red de tipo bridge para la comunicación entre contenedores

#

package.json: {
"name": "",
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"<@&1055234544183287879>/node": "^8.2.6",
"@auth/core": "^0.18.6",
"@lucia-auth/adapter-mysql": "^3.0.2",
"@nanostores/preact": "^0.5.1",
"@nanostores/react": "^0.7.2",
"@types/jwt-decode": "^3.1.0",
"astro": "^4.8.3",
"auth-astro": "^4.1.1",
"auth-core": "^1.0.3",
"cookie": "^0.6.0",
"jwt-decode": "^4.0.0",
"lucia": "^3.2.0",
"mysql2": "^3.10.0",
"nanostores": "^0.10.3",
"sweetalert2": "^11.11.1"
}
}