TienPhanDev
TienPhanDev

Reputation: 31

Hot reload stopped working after adjusting environment for work requirements

I started a new developer role a few days ago and made some environmental changes to adapt for work. Since then, my hot reload/fast refresh has just stopped working entirely. Changes don't show up even if I refresh the page manually. Only shows changes when I stop the dev server and restart it with 'npm run dev'. The triangle indicator at the bottom right should be active, showing active reload of the window (this no longer shows up consistently either, and if it does the page gets reloaded, but alas the proposed changes aren't visible)

Context:

Anybody have any ideas or clues to what I should try next? Is it related to the stuff I installed for work? Something related to VS code or WSL2? Seems so puzzling it kind of just happened overnight. Thanks for any insight or advice!

System information OS: Windows (WSL2 virtualization for VS code) Browser: Chrome Version of Next.js: 10.0.3 Version of Node.js: 14.8.0 Deployment: npm run dev for development work; amplify publish for AWS hosting

Upvotes: 3

Views: 7455

Answers (6)

RS Shonjoy
RS Shonjoy

Reputation: 265

The problem is with WSL2. I use WSL2 inside VS Code. But React JS and Next JS projects don't auto-reload. So, add a .env or .env.local (recommended) file to your root and put these lines on it:

WATCHPACK_POLLING=true
CHOKIDAR_USEPOLLING=true

Now, restart your server.

Upvotes: 1

GuTheR
GuTheR

Reputation: 81

Add a .env file or a .env.local file to your root and put this line on it:

WATCHPACK_POLLING=true 

Now, restart your server.

Upvotes: 8

EL-HADI Ayoub
EL-HADI Ayoub

Reputation: 51

In my react projects, I just add in my .env file at the root project folder the values

FAST_REFRESH=false  
CHOKIDAR_USEPOLLING=true

and it works! enjoy!

Upvotes: 1

plutoniumApples
plutoniumApples

Reputation: 57

If you run Poweshell as administrator and run

wsl.exe -l -v

This will give you th eversion of wsl your distros run on.

I am personally using Ubuntu, and this is the output

Ubuntu Running 2 docker-desktop Stopped 2 docker-desktop-data Stopped 2

To switch to wsl 1,

Run wsl.exe --set-version Ubuntu 1

and if you wanna switch back, run, wsl.exe --set-version Ubuntu 2.

This worked for me.

Upvotes: 1

4b0
4b0

Reputation: 22323

The problem is with WSL2. I use WSL2 inside VS Code; which is a big performance upgrade in the Linux environment. The problem is WSL2 is actually in a 'virtualization' and thus cannot send information from VS Code AND the browser (localhost:3000) at the same time.

It's a big issue they are working on and there is no fix yet for it. That's why fast refresh doesn't work because localhost is not receiving the changes being made. Either proxy through or revert back to WSL1 https://github.com/microsoft/WSL/issues/4769

Solution provide by OP on question section

Upvotes: 7

kitcat
kitcat

Reputation: 11

Thanks I encounter the same issue with WSL2. I just switch to windows terminal and it works.

Upvotes: 1

Related Questions