React Native: ReferenceError: Can not find the variable: require (line 1 in the generated package)


I created a sample app in react native using following guide

React native android

But when i Run react-native run-android. I am getting following exception.

 11-25 16:10:35.326 1796-1897/com.awesome E/ReactNative: Got JS Exception: ReferenceError: Can't find variable: require
11-25 16:10:35.327 1796-1897/com.awesome E/AndroidRuntime: FATAL EXCEPTION: mqt_js
                                                           Process: com.awesome, PID: 1796

com.facebook.react.bridge.JSExecutionException: ReferenceError: Can't find variable: require (line 1 in the generated bundle)
                                                           at com.facebook.react.bridge.ReactBridge.loadScriptFromAssets(Native Method)
                                                           at com.facebook.react.bridge.JSBundleLoader$1.loadScript(
                                                           at com.facebook.react.bridge.CatalystInstance$
                                                           at android.os.Handler.handleCallback(
                                                           at android.os.Handler.dispatchMessage(
                                                           at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(
                                                           at android.os.Looper.loop(
                                                           at com.facebook.react.bridge.queue.MessageQueueThread$

Anybody please help me how to resolve this.

I've had the same problem, following steps from the documentation and trying to run the generated sample app, without any change.

Turned out there was something not mentioned in docs: you have to launch a server (I thought this was what the build was doing at last steps, but it was not enough).

To do so, launch in your project root folder:

react-native start