1

I'm building a Micro-services E-commerce project, I need to create a docker image for each server in my project and run them inside K8s cluster. After successfully creating images for all back-end server I tried creating a docker image for my React front-end app, every time I try creating the image this error happened.

Here is my docker configuration:

FROM node:alpine
WORKDIR /src
COPY package*.json ./
RUN npm install --silent
COPY . .
CMD ["npm ","start"];  

Here is the error:

Error: Cannot find module '/src/npm '
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Sometimes it throws an error like this:

webpack output is served from content not from webpack is served from content not from webpack is served from /app/public docker
8
  • 2
    There is an extra space inside the quotes in "npm ". Commented Aug 2, 2021 at 22:22
  • Hello @ImranAbdalla. Was that extra space the case here? Commented Aug 3, 2021 at 9:39
  • The extra space solved half of the problem but the image didn't work, the next error is still there. Commented Aug 3, 2021 at 22:23
  • Hello @ImranAbdalla. Could you tell us which version of react-scripts are you using? Commented Aug 4, 2021 at 8:28
  • 1
    I've made some research and found two possible solutions: 1. Add stdin_open: true to your docker-compose. 2. Downgrade your react-scripts to v3.4.0. Please try them in that order and let me know about the results. Commented Aug 5, 2021 at 11:20

1 Answer 1

1

This is a community wiki answer posted for better visibility. Feel free to expand it.

To resolve described issues, steps below need to be done.

  1. Upgrade Dockerfile:

    WORKDIR /src
    COPY package*.json ./
    RUN npm install --silent
    COPY . .
    CMD ["npm","start"];
    
  2. Use version 3.4.0 for react-scripts

  3. Add stdin_open: true to docker-compose file

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.