repack
repack copied to clipboard
Re.Pack v3 default listening on localhost
Environment
Not related to the environment.
Description
Re.Pack v3 uses listen(port, host)
, when the host is an empty string ''
, it leads fastify to listen on localhost.
https://github.com/callstack/repack/blob/2b6469d599ef3bab94bbb326a2438478ffc7d3d0/packages/dev-server/src/createServer.ts#L108-L110
Re.Pack v2 uses listen({ port, host })
, when the host is an empty string ''
, it'll listen on [::]
.
https://github.com/callstack/repack/blob/a9dffc1dce6d3b3641327d7c072eef9b6b05cc2a/packages/repack/src/server/BaseDevServer.ts#L208-L213
Specifying host argument on command line react-native webpack-start --host 0.0.0.0
breaks HMR because HMR will use this host to load the update file, 0.0.0.0
leads TypeError: Network request failed
.
try react-native start --host 0.0.0.0
@GitNiko This solution breaks HMR.
By default, HMR uses the IP of the debug server to get the updated file, but if I specify the host
parameter, this will override the address where HMR gets the updated file and HMR will try to go to 0.0.0.0
to get the updated file, which will inevitably fail the request and get a TypeError: Network request failed
.
TypeError: Network request failed
related to this:
http://0.0.0.0:8081/android/main.fbfa517e3f128709cbc7.hot-update.json
HMR will fetch the update infomation, check your server or network.
Maybe your scenario is in a docker container used bridge nework, and change it to host network mode.
Or --host your_ip
Yes, using --host public_ip
solves the current problem, no other exceptions have been found so far.
But I still think that the problem should be solved by Re.Pack itself, adding parameters is not a perfect solution because I need an extra step to get the public IP of the local machine.