repack icon indicating copy to clipboard operation
repack copied to clipboard

Re.Pack v3 default listening on localhost

Open jinliming2 opened this issue 1 year ago • 3 comments

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.

jinliming2 avatar Oct 06 '22 04:10 jinliming2

try react-native start --host 0.0.0.0

GitNiko avatar Oct 08 '22 02:10 GitNiko

@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.

jinliming2 avatar Oct 08 '22 13:10 jinliming2

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

GitNiko avatar Oct 09 '22 01:10 GitNiko

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.

jinliming2 avatar Oct 09 '22 16:10 jinliming2