160

I'm currently trying to get the ES6 react-native-webpack-server running on an Android emulator. The difference is I've upgraded my package.json and build.grade to use react 0.18.0, and am getting this error on boot. As far as I'm aware AppRegistry is imported correctly. Even if I were to comment out the code this error still comes up. This does work on iOS without issue.

What am I doing wrong?

EDIT: After trying other boilerplates that do support 0.18.0, I'm still coming across the same issue.

enter image description here

Dustin
  • 6,207
  • 19
  • 61
  • 93
  • I am having the same problem with 0.19 and 0.20, I have tried everything but no luck :'( Any update @Dustin? – Shprink Feb 18 '16 at 06:26
  • @Shprink I'm also getting this problem with 0.20. Also receiving this issue `One of the sources for assign has an enumerable key on the prototype chain.` – Josh Ferrara Feb 21 '16 at 04:40

30 Answers30

82

i just upgraded to react-native 0.18.1 today tough having some peer dependencies issues with 0.19.0-rc pre-release version.

Back to your question, what I did was

  1. cd android
  2. sudo ./gradlew clean (more information about how clean works here)

then back to the working directory and run react-native run-android

you should restart your npm too after that upgrade.

hope this works for you.

Kolja
  • 2,307
  • 15
  • 23
chinloong
  • 3,507
  • 1
  • 21
  • 20
  • 4
    I'm trying to run the gradlew command but it keeps telling me it can't find the Android SDK even though I have `ANDROID_HOME` in my path. I also added the `local.properties` file with `sdk.dir=`. Any ideas? – steezeburger Feb 14 '16 at 20:15
  • 76
    When giving the advice to do something like `sudo ./gradlew clean`, it would be nice to mention that it is a **huge** operation that apparently re-downloads and reinstalls the entire gradle distribution. – Szczepan Hołyszewski Mar 23 '16 at 02:12
  • 1
    getting error Module HMRClient is not a registered callable module (calling enable). I am not able see my changes those are made in js files :( – Dinesh R Rajput Nov 23 '16 at 07:21
  • To find your Android SDK location, open Android Studio and hit configure, you'll see a path at the top which is probably something like : `/Users/karim/Library/Android/sdk` – Karim Mortabit Feb 19 '17 at 04:41
  • 1
    this did nothing for me after I tried updating to RN 0.44 – SleepsOnNewspapers May 22 '17 at 19:48
  • How are you supposed to do this on windows? Sudo is for linux and mac??? – Shariq Musharaf Jun 22 '17 at 08:39
  • @steezeburger I was getting the same problem until I put local.properties in the *android* directory, not the project root directory – Mark Oct 29 '17 at 12:34
  • I cant run gradlew clean on Windows 10 – Azmeer Nov 12 '17 at 15:23
  • sudo is not required, always use minimum privilege. – Hans Poo Jan 18 '19 at 15:12
  • Getting 'FAILURE: Build failed with an exception. * Where: Script '*node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 182 with sudo. You probably don't need sudo – David Okwii Jul 04 '19 at 12:30
  • If you are using windows machine you need to do `cd android` then `./gradlew clean` then run `react-native run-android` .... – Forhad Feb 16 '20 at 04:01
  • sudo : The term 'sudo' is not recognized as the name of a cmdlet, function, script file, or operable program. – IMPixel Feb 15 '23 at 22:19
17

I had the same issue on iOS and the cause for me was that my index.ios.js was incorrect (because I copy-pasted one of the examples without looking at its contents), it was ending with a module export declaration

exports.title = ...
exports.description = ...
module.exports = MyRootComponent;

Instead of the expected

AppRegistry.registerComponent('MyAppName', () => MyRootComponent);

You could have the same issue on android with the index.android.js I guess.

Community
  • 1
  • 1
jolivier
  • 7,380
  • 3
  • 29
  • 47
16

The one main reason of this problem could be where you would have installed a plugin and forget to link it.

try this:

react-native link

Re-run your app.

Hope this will help. Please let me know in comments. Thanks.

iDevAmit
  • 1,550
  • 2
  • 21
  • 33
11

I solved this issue just by adding

import { AppRegistry } from "react-native";
import App from "./App";
import { name as appName } from "./app.json";  
AppRegistry.registerComponent(appName, () => App);

to my index.js

make sure this exists in your index.js

Omar Samman
  • 573
  • 5
  • 12
11

For me just restarting the computer fixed it. (My error was "module appRegistry is not a registered callable module (calling runapplication) js engine: hermes")

Another top answer that is missing here and might have worked was just to kill node processes:

killall -9 node

[ Module AppRegistry is not registered callable module (calling runApplication) ]

blub
  • 8,757
  • 4
  • 27
  • 38
6

I had this issue - across iOS & Android, developing on Mac - after I had been fiddling with a dependency's code in the node_modules dir.

I solved it with:

rm -rf node_modules
npm i
npx pod-install ios

Which basically just re-installs your dependencies fresh.

deeBo
  • 836
  • 11
  • 24
5

For me my issue was putting the wrong entry-file when bundling.

I was using App.js as my entry-file, hence the App couldn't find AppRegistry

Correct:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

Incorrect:

react-native bundle --platform android --dev false --entry-file App.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
tywhang
  • 299
  • 4
  • 5
  • you saved my brain ... it was days I was trying to understand why if I launched the command: `react-native bundle --platform android --dev false --entry-file index.js --bundle-output android /app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res` everything worked, while instead if I published with fastlane the app crashed with this error: `Module AppRegistry is not a registered callable module (calling runApplication)` In the build.gradle I had, probably dirt, an incorrect entryFile! Thanks again! – Nobady Nov 07 '18 at 16:13
3

Hopefully this can save someone a headache. I got this error after upgrading my react-native version. Confusingly it only appeared on the android side of things.

My file structure includes an index.ios.js and an index.android.js. Both contain the code:

AppRegistry.registerComponent('App', () => App);

What I had to do was, in android/app/src/main/java/com/{projectName}/MainApplication.java, change index to index.android:

@Override
protected String getJSMainModuleName() {
    return "index.android"; // was "index"
}

Then in app/build/build.gradle, change the entryFile from index.js to index.android.js

project.ext.react = [
    entryFile: "index.android.js" // was index.js"
]
August Lilleaas
  • 54,010
  • 13
  • 102
  • 111
dcordz
  • 160
  • 3
  • 8
3

If you are facing this error in windows with android

open your root directory app folder and move into android folder .

cd android 
gradlew clean         

start your app again

react-native run-android 
General Grievance
  • 4,555
  • 31
  • 31
  • 45
2

I don't know why, but when I move AppRegistry.registerComponent from the index.js file that is included in index.android.js to reside inside index.android.js directly, it seems to work.

Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57
sofou
  • 21
  • 2
2

restart packager worked for me. just kill react native packager and run it again.

Ahmad Dehnavi
  • 1,483
  • 1
  • 17
  • 20
2

Check to see if you are not directly rendering something inside SafeAreaView

Ensure you are following this format

<SafeAreaView>
    <View>
       {children}
    </View>
</SafeAreaView>
Azeezat Raheem
  • 531
  • 6
  • 14
2

Please use Below mention : pakage

"react-native-reanimated": "^2.2.4",

1

If you are using some of the examples they might not work

Here is my version for scroll view

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */

import React, {
  AppRegistry,
  Component,
  StyleSheet,
  Text,
  View,
  ScrollView,
  TouchableOpacity,
  Image
} from 'react-native';

class AwesomeProject extends Component {
  render() {
    return (
        <View>
          <ScrollView
            ref={(scrollView) => { _scrollView = scrollView; }}
            automaticallyAdjustContentInsets={false}
            onScroll={() => { console.log('onScroll!'); }}
            scrollEventThrottle={200}
            style={styles.scrollView}>
            {THUMBS.map(createThumbRow)}
          </ScrollView>
          <TouchableOpacity
            style={styles.button}
            onPress={() => { _scrollView.scrollTo({y: 0}); }}>
            <Text>Scroll to top</Text>
          </TouchableOpacity>
        </View>
    );
  }
}

var Thumb = React.createClass({
  shouldComponentUpdate: function(nextProps, nextState) {
    return false;
  },
  render: function() {
    return (
      <View style={styles.button}>
        <Image style={styles.img} source={{uri:this.props.uri}} />
      </View>
    );
  }
});

var THUMBS = [
'http://loremflickr.com/320/240?random='+Math.round(Math.random()*10000) + 1,
'http://loremflickr.com/320/240?random='+Math.round(Math.random()*10000) + 1,
'http://loremflickr.com/320/240?random='+Math.round(Math.random()*10000) + 1
];

THUMBS = THUMBS.concat(THUMBS); // double length of THUMBS
var createThumbRow = (uri, i) => <Thumb key={i} uri={uri} />;

var styles = StyleSheet.create({
  scrollView: {
    backgroundColor: '#6A85B1',
    height: 600,
  },
  horizontalScrollView: {
    height: 120,
  },
  containerPage: {
    height: 50,
    width: 50,
    backgroundColor: '#527FE4',
    padding: 5,
  },
  text: {
    fontSize: 20,
    color: '#888888',
    left: 80,
    top: 20,
    height: 40,
  },
  button: {
    margin: 7,
    padding: 5,
    alignItems: 'center',
    backgroundColor: '#eaeaea',
    borderRadius: 3,
  },
  buttonContents: {
    flexDirection: 'row',
    width: 64,
    height: 64,
  },
  img: {
    width: 321,
    height: 200,
  }
});

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
1

I uninstalled it on Genymotion. Then run react-native run-android to build the app. And it worked. Do try this first before running sudo ./gradlew clean, it will save you a lot of time.

kklw
  • 858
  • 3
  • 13
  • 28
1

npm start -- --reset-cache

Probably port is already in use. I face similar issue when i first run react-native run-android and then npm start. I solve it like this: First, get the id of the process running in port 8081: sudo lsof -i :8081

1

I had the same problem several times. The following solutions are solved my problem. I have listed out them according to complexity.

  1. Restart the computer and see whether the problem is out

  2. If it still exists, try to kill the process on running port usually 8080

    netstat -ano | findstr 8080

     taskkill /F /PID <PID>
    
  3. If it still exists, go to 'android' directory as follow and go further

    cd android

    ./gradlew clean

and start node

npm start

then run npx react-native run android or expo stat and press 'a'

Hope you will OK with the above issues.

1

My issue was cleared by following these commands (OS: Windows 10).

  1. cd android
  2. gradlew clean
  3. cd..
  4. npx react-native run-android
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
1

I had the same problem and that because I was calling Stylesheet without importing..

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 21 '22 at 01:24
0

In my case, my index.js just points to another js instead of my Launcher js mistakenly, which does not contain AppRegistry.registerComponent().

So, make sure the file yourindex.jspoint to register the class.

yao
  • 300
  • 3
  • 11
0

My issue was fixed by increasing my inotify max_user_watches:

sudo sysctl fs.inotify.max_user_watches=1280000
nobane
  • 76
  • 1
  • 7
0

For me it was a issue with react-native dependency on next version of react package, while in my package.json the old one was specified. Upgrading my react version solved this problem.

requirunt
  • 55
  • 1
  • 5
0

For me just i linked with react native as this way : react-native link

Asma_Kh
  • 93
  • 2
  • 15
0

I got this error in Expo because I had exported the wrong component name, e.g.

const Wonk = props => (
  <Text>Hi!</Text>
)

export default Stack;
duhaime
  • 25,611
  • 17
  • 169
  • 224
0

I solved this problem by doing the following:

  1. cd android
  2. ./gradlew clean
  3. taskkill /f /im node.exe
  4. uninstall app from android
Hamid Shoja
  • 3,838
  • 4
  • 30
  • 45
0

If you are using windows machine you need to do cd android then ./gradlew clean then run react-native run-android

Forhad
  • 1,460
  • 10
  • 12
0

This can because of any cache issue from node, pod ,gradle anywhere, its better to do an entire clean slate cleanup, for this use react native clean project

Pranay Dutta
  • 2,483
  • 2
  • 30
  • 42
0

A typical reason I get this error is when I import badly a component (like with the wrong name). Same if I export it badly and them import it correctly. This may seem primitive but to err is human and many times this error appears, if cleaning the project and restarting it doesn't fix it, it can be this.

Dragos
  • 46
  • 1
  • 6
0

delete android/.gradle and reac-module. than run yarn install and run-android

0

on iOS I have got this issue.

but after cleaning the build folder by entering command+shift+k and building it again worked for me

you should also check the scheme should be debug

Azaz Ahmed
  • 91
  • 1
  • 5