Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: ReferenceError: Can't find variable: require (line 1 in the generated bundle)

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(JSBundleLoader.java:32)
                                                           at com.facebook.react.bridge.CatalystInstance$2.run(CatalystInstance.java:138)
                                                           at android.os.Handler.handleCallback(Handler.java:739)
                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                           at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
                                                           at android.os.Looper.loop(Looper.java:148)
                                                           at com.facebook.react.bridge.queue.MessageQueueThread$1.run(MessageQueueThread.java:137)
                                                           at java.lang.Thread.run(Thread.java:818)

Anybody please help me how to resolve this.

like image 806
Santhi Bharath Avatar asked Nov 28 '22 20:11

Santhi Bharath


2 Answers

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
like image 142
kik Avatar answered Dec 05 '22 05:12

kik


I had the same problem and the fix was starting adb. Did you run adb reverse tcp:8081 tcp:8081 ?

like image 37
raluca Avatar answered Dec 05 '22 03:12

raluca