前提是在使用以下环境

名称 版本 icon
React native debugger V0.10 使用 Expo 的错误 WebSocket connection to 'ws://localhost:19002/debugger-proxy?role=debugger&name=Chrome' failed: Error during WebSocket handshake: Unexpected response code: 400
React devTools latest 使用 Expo 的错误 WebSocket connection to 'ws://localhost:19002/debugger-proxy?role=debugger&name=Chrome' failed: Error during WebSocket handshake: Unexpected response code: 400
Expo ~37.0.3 => 37.0.8 使用 Expo 的错误 WebSocket connection to 'ws://localhost:19002/debugger-proxy?role=debugger&name=Chrome' failed: Error during WebSocket handshake: Unexpected response code: 400

错误:


WebSocket connection to 'ws://localhost:19002/debugger-proxy?role=debugger&name=Chrome' failed: Error during WebSocket handshake: Unexpected response code: 400

接照本次的错误,是因为React native debugger无法成功访问ws://localhost:19002。

而很多开发将它定义为 WebSocket 的问题或是代理的问题。

答案连接了错误的端口导致。(但是如果并非这个问题,解决方案建议 expo diagnostics 诊断环境并重新安装来测试错误的重现。 )

下面我简单的描述端口的使用。

首先,运行 yarn start :

使用 Expo 的错误 WebSocket connection to 'ws://localhost:19002/debugger-proxy?role=debugger&name=Chrome' failed: Error during WebSocket handshake: Unexpected response code: 400

  • Metro Bundler on port 19001 —— 绑定React native debugger 的端口

  • http://localhost:19002 —— 浏览器 可视化DevTools

  • exp://127.0.0.1:19000 in iOS simulator —— 虚拟器使用的端口

有些问题可能很小,但它就是欺负末懂者,它会纠缠很久。

相关文章: