简体   繁体   中英

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.

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

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

You can also check if you have react.gradle file in your gradle files. Try bundling the asset manually if you do not have this file.

Reference: https://facebook.github.io/react-native/docs/signed-apk-android.html#content

确保您的手机和机器在同一网络中

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM