You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CRA 5.0 fails to hot-reload in a docker container built #11879
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 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
I found a workaround for a similar issue in #11897 (comment), does it resolve the problem for you?
Not working for me.
Same error : (node:27) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP MIDDLEWARE] DeprecationWarning: 'AfterStep Middleware' option is deprecated. Please use the 'setupMiddlewares'
I am on windows, That may cause the issue.
Latest Node docker image : Node.js v17.4.0
Workaround with previous version :
Need react-script : 4.0.3
I have also to fix : error:03000086:digital envelope routines::initialization error --> --openssl-legacy-provider
But need to press F5 for refresh
EDIT package.json was missing "eslintConfig": { "extends": [ "react-app", "react-app/jest" ]}
I found a workaround for a similar issue in #11897 (comment), does it resolve the problem for you?
Not working for me. Same error : (node:27) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP MIDDLEWARE] DeprecationWarning: 'AfterStep Middleware' option is deprecated. Please use the 'setupMiddlewares'
I am on windows, That may cause the issue. Latest Node docker image : Node.js v17.4.0
Workaround with previous version :
Need react-script : 4.0.3
I have also to fix : error:03000086:digital envelope routines::initialization error --> --openssl-legacy-provider
But need to press F5 for refresh EDIT package.json was missing "eslintConfig": { "extends": [ "react-app", "react-app/jest" ]}
Can confirm that downgrading react-scripts to 4.0.3 resolves the issue.
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.
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.
Reacted by soiswis, nilscrls, Nik Tomazic, Joachim Birkelund Fredheim, Saša Đurić, hbh7, Michael Gordon, Quentin, Scott deVries, Mihai Stan and 14 more
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
A workaround for me was moving the folder project to the Ubuntu WSL folders, i mean /mnt/d/projects/new-project (win10) -> /home/shuni/new-project (linux) and it worked.
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 WDS_SOCKET_PATH for two different containers, along with exposing their dev 3000 ports to different host ports in case I needed to directly access:
...which then falls back to using the default path, but a different port... allowing hot reload to work. CHOKIDAR_USEPOLLING was removed. note I have a traefik proxy in front of these via docker also.
Reacted by Nick Norrell, Ivan, Chu Van Loc, Igor and jaimeshalom
Running React container with either -e CHOKIDAR_USEPOLLING=true or -e WATCHPACK_POLLING=true solves the issue for me depending on the Webpack version I am using (I believe it was after version 5.72.1 that Webpack started using its own files watcher(Watchpack) as a replacement for Chokidar).
Could run it like so if you are unsure about the Webpack version: docker run -e CHOKIDAR_USEPOLLING=true -e WATCHPACK_POLLING=true <your_container_image>
Could also, of course, add those variables into the dockerfile so they are provided during the building of the image:
Reacted by Alexander Gschwend, El_makong, Valerii Vitenko, Lucas Ferreyra Vera, Jose Otero (Oteroweb), zabihexes, Jay, Josh Byster, jaimeshalom, David Roth and 5 more
Reacted by Storm-Front, Vinícius Costa, Antsthebul, Valerii Vitenko, Jose Otero (Oteroweb), BjAlvestad, zabihexes, Josh Byster, Rui Ren and David Roth
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) .
Reacted by Stijn Hoskens, Anthony, DariusBlueBot and Tom Radford
WATCHPACK_POLLING=true seems to be sufficient for me. Running Docker in WSL, having my source code in a Windows folder, running the frontend behind a reverse proxy (nginx).
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.
Running React container with either -e CHOKIDAR_USEPOLLING=true or -e WATCHPACK_POLLING=true solves the issue for me depending on the Webpack version I am using (I believe it was after version 5.72.1 that Webpack started using its own files watcher(Watchpack) as a replacement for Chokidar).
Could run it like so if you are unsure about the Webpack version: docker run -e CHOKIDAR_USEPOLLING=true -e WATCHPACK_POLLING=true <your_container_image>
Could also, of course, add those variables into the dockerfile so they are provided during the building of the image:
changed the title [-]CRA 5.0 fails to hot-reload in a docker container built On shoulders of _____[/-][+]CRA 5.0 fails to hot-reload in a docker container built[/+]on Jun 4, 2024
Activity
monophthongal commentedon Jan 7, 2022
I found a workaround for a similar issue in #11897 (comment), does it resolve the problem for you?
lesliewubbel commentedon Jan 7, 2022
@monophthongal I will have to give this a shot!! When I get off work for the weekend
zaras00tra commentedon Jan 20, 2022
Not working for me.
Same error :
(node:27) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP MIDDLEWARE] DeprecationWarning: 'AfterStep Middleware' option is deprecated. Please use the 'setupMiddlewares'I am on windows, That may cause the issue.
Latest Node docker image :
Node.js v17.4.0Workaround with previous version :
But need to press F5 for refreshEDIT
package.jsonwas missing"eslintConfig": { "extends": [ "react-app", "react-app/jest" ]}reverted to react-scripts 4.0.3 after running into these issues: reac…
duplxey commentedon Jan 28, 2022
Can confirm that downgrading
react-scriptsto4.0.3resolves the issue.If anyone finds a more convenient solution, please tag me.
sarang997 commentedon Feb 4, 2022
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.
duplxey commentedon Feb 4, 2022
He's using an older version of
react-scripts("3.4.3").https://github.com/veryacademy/docker-mastery-with-django/blob/main/Part-6%20Nginx%20React%20and%20Django%20Gunicorn/Final/react/blogapi/package.json#L13
The problem is with CRA 5.0.
marlonchalegre commentedon Feb 9, 2022
Any news in this issue?
axhatem commentedon Feb 19, 2022
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
Vadim2308 commentedon Feb 19, 2022
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)
shuni95 commentedon Feb 19, 2022
A workaround for me was moving the folder project to the Ubuntu WSL folders, i mean
/mnt/d/projects/new-project (win10) -> /home/shuni/new-project (linux)and it worked.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.
Vadim2308 commentedon Feb 20, 2022
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
EJIqpEP commentedon Feb 26, 2022
Still no solution except of downgrading to 4.0.3? People stop breaking things pls.
36 remaining items
shawnwall commentedon May 2, 2022
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
WDS_SOCKET_PATHfor two different containers, along with exposing their dev 3000 ports to different host ports in case I needed to directly access: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.
CHOKIDAR_USEPOLLINGwas removed. note I have atraefikproxy in front of these via docker also.DarinDev1000 commentedon Jul 19, 2022
I also have this issue. Is this something that needs to be patched?
endvvell commentedon Jul 24, 2022
Running React container with either
-e CHOKIDAR_USEPOLLING=trueor-e WATCHPACK_POLLING=truesolves the issue for me depending on the Webpack version I am using (I believe it was after version 5.72.1 that Webpack started using its own files watcher(Watchpack) as a replacement for Chokidar).Could run it like so if you are unsure about the Webpack version:
docker run -e CHOKIDAR_USEPOLLING=true -e WATCHPACK_POLLING=true <your_container_image>Could also, of course, add those variables into the dockerfile so they are provided during the building of the image:
sohagmahin commentedon Sep 6, 2022
faced same isssue. hot loading not working on react-script 5.0.0
Antsthebul commentedon Sep 24, 2022
@svitan0k fix worked for me! Thanks! Running Docker Desktop on Windows
AObzh commentedon Oct 27, 2022
added
WDS_SOCKET_HOST=127.0.0.1and seems it solve the problem.andypan-twn commentedon Nov 10, 2022
Add
UIDandGIDvalues and it solves the issue for me on Mac.command:
docker file:
GustavoContreiras commentedon Dec 23, 2022
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) .
lesliewubbel commentedon Dec 23, 2022
Wow thank you very much after a year we have solution, I am going to test it next and then close the issue
shoskensMagics commentedon Jan 17, 2023
WATCHPACK_POLLING=trueseems to be sufficient for me. Running Docker in WSL, having my source code in a Windows folder, running the frontend behind a reverse proxy (nginx).acoory commentedon Feb 6, 2023
Thank you very much you saved me a long evening of research I am saved
hlgrondijs commentedon Mar 8, 2023
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.
flaviobogila commentedon Jun 4, 2024
I've already try to use CHOKIDAR_USEPOLLING and not worked, but WATCHPACK_POLLING worked perfectly, thanks!
[-]CRA 5.0 fails to hot-reload in a docker container built On shoulders of _____[/-][+]CRA 5.0 fails to hot-reload in a docker container built[/+]