Improve error message when devserver is not running

Summary:
public

If Hot Loading is enabled bu the packager server is not running, as the user updates files he'll see red boxes caused by the HMR runtime. The error those red boxes show is pretty weird for the end user. Lets improve the feedback we give!.

Reviewed By: vjeux

Differential Revision: D2795534

fb-gh-sync-id: dcc39e6682e0603bf10d0f5e623433262b745660
This commit is contained in:
Martín Bigio 2016-01-04 09:55:09 -08:00 committed by facebook-github-bot-6
parent 44f7a00e95
commit 54f2586735
1 changed files with 18 additions and 5 deletions

View File

@ -21,19 +21,32 @@ const HMRClient = {
invariant(platform, 'Missing required parameter `platform`'); invariant(platform, 'Missing required parameter `platform`');
invariant(bundleEntry, 'Missing required paramenter `bundleEntry`'); invariant(bundleEntry, 'Missing required paramenter `bundleEntry`');
// TODO(martinb) receive host and port as parameters
const host = 'localhost';
const port = '8081';
// need to require WebSocket inside of `enable` function because the // need to require WebSocket inside of `enable` function because the
// this module is defined as a `polyfillGlobal`. // this module is defined as a `polyfillGlobal`.
// See `InitializeJavascriptAppEngine.js` // See `InitializeJavascriptAppEngine.js`
const WebSocket = require('WebSocket'); const WebSocket = require('WebSocket');
// TODO(martinb): parametrize the url and receive entryFile to minimize
// the number of updates we want to receive from the server.
const activeWS = new WebSocket( const activeWS = new WebSocket(
'ws://localhost:8081/hot?platform=' + platform + '&bundleEntry=' + `ws://${host}:${port}/hot?platform=${platform}&` +
bundleEntry.replace('.bundle', '.js') `bundleEntry=${bundleEntry.replace('.bundle', '.js')}`
); );
activeWS.onerror = (e) => { activeWS.onerror = (e) => {
console.error('[Hot Module Replacement] Unexpected error', e); throw new Error(
`Hot loading isn't working because it cannot connect to the development server.
Ensure the following:
- Node server is running and available on the same network
- run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate
URL: ${host}:${port}
Error: ${e.message}`
);
}; };
activeWS.onmessage = (m) => { activeWS.onmessage = (m) => {
eval(m.data); // eslint-disable-line no-eval eval(m.data); // eslint-disable-line no-eval