Gatsby hot-reload failed to connect to 127.0.0.1 on WSL2

Viewed 251

When running in debug mode, I think the hot-reload is failing to connect on 127.0.0.1, because (in WSL2) should be localhost. How can I change this to localhost?

How to solve this? I think that is a webpack configuration.

1 Answers

Change your package.json running command to:

"develop": "gatsby develop -H 0.0.0.0"

Dealing with WSL could be tricky because of the running host and port since it's a subsystem in Windows. With the command above you are setting the host (-H flag) as 0.0.0.0. Thereby, you can access your dev environment on other devices on the same network.

To access Gatsby on your local machine, use either http://localhost:8000 or the “On Your Network” URL.

You can check for further information in Gatsby-cli documentation to polish your host and port if needed.

Related