-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRA 5.0 fails to hot-reload in a docker container built #11879
Comments
I found a workaround for a similar issue in #11897 (comment), does it resolve the problem for you? |
@monophthongal I will have to give this a shot!! When I get off work for the weekend |
Not working for me. I am on windows, That may cause the issue. Workaround with previous version :
|
…book/create-react-app#11897, facebook/create-react-app#11879. Hot reload for frontend now working completes the containerized development environment for phonebook app created when using docker-compose.dev.yml
Can confirm that downgrading If anyone finds a more convenient solution, please tag me. |
Check out this tutorial https://www.youtube.com/watch?v=xtllpDEOw4w&t=913s . At some point he creates docker-compose.yml file which actully updates the container file when you make changes to a file in the code editor. |
He's using an older version of The problem is with CRA 5.0. |
Any news in this issue? |
I did try only on the last version of the CRA and when i change a source file it updates on Linux container but not on the npm started instance and the web page doesnt change even after reloading it. I dont know if the samedi thing happens to you. UPDATE; I did the test with the 4.0.3 and that one worked well |
It doesn't work for me either...tried react scripts 4.0.3, different versions of NODE, hot reboot doesn't work...kick me if there is a solution) |
A workaround for me was moving the folder project to the Ubuntu WSL folders, i mean This is my Dockerfile
and my docker-compose.yml
I remember i've read that was an issue related with the filesystem or something like that. |
Thanks for the decision! I found an answer last night that says this problem is only on windows with WSL. On Linux everything is fine. I will try to |
Still no solution except of downgrading to 4.0.3? People stop breaking things pls. |
Same problem with me with CRA5. However, I see something strange while running the containerised app through docker desktop dev environment preview. I believe it is doing the same thing running a dev env with container volume and the hot reload works. Trying to figure out how it works in dev env preview. |
For a while, everything worked fine with 4.0.3 and even 5.0.0, but a few days ago after a docker crash, and remove all containers, hot reload also stopped working on all versions of CRA |
Same issue here. Downgrading react-scripts@5.0.0 to react-scripts@4.0.3 worked for me. I am using docker in windows. |
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",
... |
@rmarcelo that works great with my app, thanks! |
create basic CRA 5.0 app, and add this file, hot reload still don`t work ( WebSocketClient.js:16 WebSocket connection to 'ws://localhost:3000/ws' failed: Docker Desktop 4.6.0 (75818) is currently the newest version available. docker file services: node: tty: true stdin_open: true image: node:14.16.1-alpine working_dir: /var/www volumes: - .:/var/www ports: - 9999:3000 command: sh -c "npm i && npm start" package.json { "name": "test-cra-5-docker", "version": "0.1.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.16.2", "@testing-library/react": "^12.1.4", "@testing-library/user-event": "^13.5.0", "react": "^17.0.2", "react-dom": "^17.0.2", "react-scripts": "5.0.0", "web-vitals": "^2.1.4" }, "scripts": { "start": "node ./setup && react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] } } Windows Windows 10 Pro version 21H2 collection 19044.1586 Windows Feature Experience Pack 120.2212.4170.0 |
@Makentosh WDS_SOCKET_PORT=9999 |
WDS_SOCKET_PORT=9999 maybe a docker problem, or some cache? |
@Makentosh How do you access it in the browser? do you use reverse proxy? could you try WDS_SOCKET_PORT=0 ? |
@rmarcelo WDS_SOCKET_PORT=0 also does not work log in docker audited 1272 packages in 6.062s 169 packages are looking for funding run `npm fund` for details found 1 moderate severity vulnerability run `npm audit fix` to fix them, or `npm audit` for details 7m .....] \ prepare:www: sill install printInstalled > test-cra-5-docker@0.1.0 start /var/www > node ./setup && react-scripts start (node:43) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option. (Use `node --trace-deprecation ...` to show where the warning was created) (node:43) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option. Starting the development server... Compiled successfully! You can now view test-cra-5-docker in the browser. Local: http://localhost:3000 On Your Network: http://172.21.0.2:3000 Note that the development build is not optimized. To create a production build, use npm run build. assets by path static/js/*.js 1.48 MiB asset static/js/bundle.js 1.47 MiB [emitted] (name: main) 1 related asset asset static/js/node_modules_web-vitals_dist_web-vitals_js.chunk.js 6.94 KiB [emitted] 1 related asset asset index.html 1.67 KiB [emitted] asset asset-manifest.json 458 bytes [emitted] runtime modules 31.3 KiB 15 modules modules by path ./node_modules/ 1.35 MiB 99 modules modules by path ./src/ 13.5 KiB modules by path ./src/*.css 8.82 KiB ./src/index.css 2.72 KiB [built] [code generated] ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./src/index.css 1.37 KiB [built] [code generated] ./src/App.css 2.72 KiB [built] [code generated] ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./src/App.css 2 KiB [built] [code generated] modules by path ./src/*.js 4.69 KiB ./src/index.js 1.74 KiB [built] [code generated] ./src/App.js 1.59 KiB [built] [code generated] ./src/reportWebVitals.js 1.36 KiB [built] [code generated] webpack 5.70.0 compiled successfully in 20516 ms |
This worked for me - I'm using a reverse proxy |
@Makentosh Are you still getting this error in console, can you post what error are you getting now ?
|
@rmarcelo There is no error, but hot reload does not work |
The setup.js that I posted has this, maybe you're not getting development on your NODE_ENV, try to remove that and check if it works.
If that doesn't work try checking if you have this file on your node_modules:
If yes, check if you have this exact text on that webpack.config.js
|
@rmarcelo |
I tried to install version 4.0.3 separately, It helped me
and set WDS_SOCKET_PORT = current port on docker |
Hot reloading is broken in react-scripts, more information: facebook/create-react-app#11879
Hot reloading is broken in react-scripts, more information: facebook/create-react-app#11879
Hot reloading is broken in react-scripts, more information: facebook/create-react-app#11879
Hot reloading is broken in react-scripts, more information: facebook/create-react-app#11879
Hot reloading is broken in react-scripts, more information: facebook/create-react-app#11879
Same issue here. @rmarcelo's workaround works for me, but I hope to see this fixed shortly. |
I just wanted to share my "fix" for this for those of you who may be using docker compose and are possibly running multiple frontend containers. Originally I had to custom set two different
This broke recently as everyone knows. My workaround ended up being:
...which then falls back to using the default path, but a different port... allowing hot reload to work. |
rmarcello's solution worked for my situation with some additional configuration. I came from CRA 4.0.0. The project is a mono repo with each package being built as it's own container inside a larger container. It uses a reverse proxy to access the server. It's also worth noting I'm on Windows 11, though the reason the project is built the way it is, is to minimize OS related development issues. I already had ...
// if (process.env.NODE_ENV === 'development') {
if (process.env.NODE_ENV !== 'production') {
... |
I also have this issue. Is this something that needs to be patched? |
Running React container with either Could run it like so if you are unsure about the Webpack version: Could also, of course, add those variables into the dockerfile so they are provided during the building of the image:
|
faced same isssue. hot loading not working on react-script 5.0.0 |
@svitan0k fix worked for me! Thanks! Running Docker Desktop on Windows |
added |
Add command:
docker file:
|
After almost 24 hours trying to setup this dockerized react app with webpack, typescript and hot reload I finally did it. I'm on a Windows 10 and this is my setup: Folder structure
package.json
Dockerfile
docker-compose.yml
.env
You can use VSCode Dev Containers extension to check if you are mounting/binding the volume/folders correctly (changes in a source file in your local machine should trigger changes in the same source file in the docker container) . |
Wow thank you very much after a year we have solution, I am going to test it next and then close the issue |
|
Thank you very much you saved me a long evening of research I am saved |
Unfortunately the solution by @GustavoContreiras does not seem to work on my Mac. Hot reload works fine on the host system, but when containerized, no hot-reload is happening. Inspecting the websocket used for the reload functionality reveals there are no "invalid" packets being received when a file is changed. The volume is mounted properly (inspecting the file in the container reveals it DID update) and I also selected gRPC FUSE as mentioned above. |
I've already try to use CHOKIDAR_USEPOLLING and not worked, but WATCHPACK_POLLING worked perfectly, thanks! |
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
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
#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
The text was updated successfully, but these errors were encountered: