question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CRA 5.0 fails to hot-reload in a docker container built On shoulders of _____

See original GitHub issue

Apolgozies for being super inexperience, there many layers and dont know which part of the problem I should debug like is it docker, is npm package manager, is it react-scripts@5.0.0 itself?

Describe the bug

CRA 5.0 fails to hot-reload in a docker container with using CHOKIDAR_USEPOLLING

Yes its mounted correctly. I checked many many times.

Environment

OS:Windows 10 VScode WSL Docker 4.2.0

Steps to reproduce

Lets say you

npx create-react-app my-app

you start the server it works normally, however your workflow at a company uses docker containers with react for development

you use the newer version of react-scripts@5.0.0

dockerfile created

WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
ENV PORT=3000
EXPOSE 3000
CMD ["npm", "run", "start"]

docker build -t react-test-2 ./

docker run -e CHOKIDAR_USEPOLLING=true -v D:\test-react-app\my-app:/app -it --name react-test-app2 -p 3000:3000 react-test-2

you triple check that bind mount is working. Try different directories, check docker, check Chokidar library,

So I went back to the version that worked with in react-scripts@4.0.3 it somehow works, try again different techniques

I see when I ran react-script@5.0.0

I get (node:31) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP MIDDLEWARE] DeprecationWarning: ‘AfterStep Middleware’ option is deprecated. Please use the ‘setupMiddlewares’ option.

Or the webpack log displays on start up don’t know if its a issue or bug yet related https://github.com/facebook/create-react-app/issues/11871

Or maybe it’s

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I’ll try to do my best with it!

Expected behavior

React to hot-reload as it did in react-scripts@4.0.3 inside a mounted volume docker container

Actual behavior

React-scripts@5.0.0 fails to hot-reload inside a mounted volume docker container

Reproducible demo

https://github.com/Gresliebear/Reproducible-demo

Solution

Downgrade react-scripts@5.0.0 to react-scripts@4.0.3

However your will expose to vulerabilites which 2 are critical

image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:22
  • Comments:53

github_iconTop GitHub Comments

23reactions
rmarcelocommented, Mar 16, 2022

Just sharing my workaround for CRA 5.0

// setup.js
const fs = require('fs');
const path = require('path');

if (process.env.NODE_ENV === 'development') {
  const webPackConfigFile = path.resolve('./node_modules/react-scripts/config/webpack.config.js');
  let webPackConfigFileText = fs.readFileSync(webPackConfigFile, 'utf8');

  if (!webPackConfigFileText.includes('watchOptions')) {
    if (webPackConfigFileText.includes('performance: false,')) {
      webPackConfigFileText = webPackConfigFileText.replace(
        'performance: false,',
        "performance: false,\n\t\twatchOptions: { aggregateTimeout: 200, poll: 1000, ignored: '**/node_modules', },"
      );
      fs.writeFileSync(webPackConfigFile, webPackConfigFileText, 'utf8');
    } else {
      throw new Error(`Failed to inject watchOptions`);
    }
  }
}
// package.json
"scripts": {
    "start": "node ./setup && react-scripts start",
...
22reactions
marlonchalegrecommented, Feb 9, 2022

Any news in this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React hot reload doesn't work in docker container
Currently, if I create a file it recompiles, but if I change something in a file it does not. Also, I didn't change...
Read more >
Live Reload with Docker and React | by Chavez Harris - Medium
Getting live reload to work in a React docker setup can be a bit difficult and up to a point seem impossible but...
Read more >
How to Hot-Reload in ReactJS Docker? - Tutorialspoint
Hot-Reloading is adding dynamic functionality to the react application on the web browser. This means if we change something in the code of ......
Read more >
Docker+create-react-appで環境構築すると編集内容が更新 ...
(CRA 5.0 fails to hot-reload in a docker container built On shoulders of _____ #11879より引用). 次に、ホスト側の front フォルダ直下に ...
Read more >
Create React App dev server can't hot load changes in docker ...
However, whenever I make source code changes from the host machine, the development server running in the container simply does not reload ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found