user11669757
user11669757

Reputation:

What is the root cause of "[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null"

Error:

[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null. 

I got it when I try to run my app in expo with npm start

I got it last night, I fixed it and it worked till one hour ago, but now it’s here again.

I read other topics about the same error, but it doesn’t work for me.

my app.js code

import React from 'react';
import { Platform, StatusBar, StyleSheet, View, AsyncStorage} from 'react-native';
import { AppLoading, Asset, Font, Icon } from 'expo';

import AppNavigator from './navigation/AppNavigator';
import MainTabNavigator from './navigation/MainTabNavigator';
import * as firebase from 'firebase';



export default class App extends React.Component {
  state = {
    isLoadingComplete: false,
    isAuthenticationReady: false,
    isAuthenticated: false,
  };

  render() {
    if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) {
      return (
        <AppLoading
          startAsync={this._loadResourcesAsync}
          onError={this._handleLoadingError}
          onFinish={this._handleFinishLoading}
        />
      );
    } else {
      return (
        <View style={styles.container}>
          {Platform.OS === 'ios' && <StatusBar barStyle="default" />}
          <AppNavigator />
        </View>
      );
    }
  }

  _loadResourcesAsync = async () => {
    return Promise.all([
      Asset.loadAsync([
        require('./assets/images/robot-dev.png'),
        require('./assets/images/robot-prod.png'),
      ]),
      Font.loadAsync({
        // This is the font that we are using for our tab bar
        ...Icon.Ionicons.font,
        // We include SpaceMono because we use it in HomeScreen.js. Feel free
        // to remove this if you are not using it in your app
        'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
      }),
    ]);
  };


Upvotes: 1

Views: 6695

Answers (1)

Daniel
Daniel

Reputation: 15483

AsyncStorage no longer in react-native library:

import { Platform, StatusBar, StyleSheet, View, AsyncStorage} from 'react-native';

remove AsyncStorage as a module and do npm install --save @react-native-community/async-storage

and then import into your file like so:

import AsyncStorage from '@react-native-community/async-storage';

Upvotes: 2

Related Questions