/bin/sh: 1: react-scripts: not found in development ENV reactjs

Advertisements

I want to use Docker in development mode, This is my Docker file.

FROM node:18.12.1

WORKDIR /usr/src/app

COPY package*.json ./

RUN yarn install

COPY . .


EXPOSE 3000


CMD ["yarn", "start"]

and my docker-compose is:

version: '3'

services:
  mlm_frontend:
    build:
      context: .
      dockerfile: Dockerfile.dev
    volumes:
      - ./:/usr/src/app
    ports:
      - "3000:80"

I have an error /bin/sh: 1: react-scripts: not found

>Solution :

I believe this is likely because your node_modules folder is being overridden by the volume you mount with Docker Compose..

I’ll suggest you keep the node_modules from your Docker container, by telling Docker Compose to use the node_modules folder that gets created inside your Docker container, not the one from your computer. You can modify your docker-compose.yml file like this:

version: '3'
services:
  mlm_frontend:
    build:
      context: .
      dockerfile: Dockerfile.dev
    volumes:
      - ./:/usr/src/app
      - /usr/src/app/node_modules
    ports:
      - "3000:80"

Also, make sure you’re using the right Dockerfile name in your docker-compose.yml.

Leave a ReplyCancel reply