async-storage: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null

Current behavior

The common AsyncStorage null exception.

Repro steps

I’m building a small app that was initialized via Expo. I’m trying to use AsyncStorage for my redux store and for a framework. Currently, I have it working for testing using the old react-native module for storage. But I’m trying to make it work with the current, community, version. Steps I took are as follows:

  • npm i @react-native-community/async-storage
  • expo eject
  • react-native link @react-native-community/async-storage
  • cd ios && pod install
  • react-native run-ios
  • expo start -c
  • Removed npm_modules and reinstalled.

One error I receive after running react-native run-ios is the following, but I have already run pod install in the ios folder, and re-running tells me that there are 54 (55) modules install (55 if I link async storage).

error Could not find the following native modules: RNCMaskedView, react-native-netinfo, RNGestureHandler, RNReanimated, react-native-safe-area-context, RNScreens, RNSVG. Did you forget to run “pod install” ?

I’ve also tried referencing the native modules in the podfile, after use_react_native!. But that hasn’t worked either

 require_relative '../node_modules/react-native/scripts/autolink-ios.rb'
 require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
 use_react_native!
 use_native_modules!

Linking tells me that the module is already linked. I have also tried unlinking and running that way, same issue. Simple code I am using is as follows (looks like v2 may be a little different?):

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

// Redux Persistence Config.
const persistConfig = {
  key: config.redux.persistKey,
  storage: AsyncStorage
}

Environment

  • Async Storage version: 1.8.0
  • React-Native version: 0.61.4
  • Platform tested: iOS
  • Expo version: 36.0.0

Podfile

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'

target 'pilogger' do
  pod 'ExpoKit',
    :git => "http://github.com/expo/expo.git",
    :tag => "ios/2.14.4",
    :subspecs => [
      "Core"
    ],
    :inhibit_warnings => true

  # Install unimodules
  require_relative '../node_modules/react-native-unimodules/cocoapods.rb'
  use_unimodules!(
    modules_paths: ['../node_modules'],
    exclude: [
      'expo-bluetooth',
      'expo-in-app-purchases',
      'expo-payments-stripe',
    ],
  )

 # Install React Native and its dependencies
 require_relative '../node_modules/react-native/scripts/autolink-ios.rb'
 use_react_native!

  pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'

  post_install do |installer|
    installer.pods_project.main_group.tab_width = '2';
    installer.pods_project.main_group.indent_width = '2';

    installer.target_installation_results.pod_target_installation_results
      .each do |pod_name, target_installation_result|

      if pod_name == 'ExpoKit'
        target_installation_result.native_target.build_configurations.each do |config|
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'EX_DETACHED=1'
          
          # Enable Google Maps support
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'HAVE_GOOGLE_MAPS=1'
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'HAVE_GOOGLE_MAPS_UTILS=1'
          
        end
      end



      target_installation_result.native_target.build_configurations.each do |config|
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
      end


      # Can't specify this in the React podspec because we need to use those podspecs for detached
      # projects which don't reference ExponentCPP.
      if pod_name.start_with?('React')
        target_installation_result.native_target.build_configurations.each do |config|
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
          config.build_settings['HEADER_SEARCH_PATHS'] ||= ['$(inherited)']
        end
      end

      # Build React Native with RCT_DEV enabled and RCT_ENABLE_INSPECTOR and
      # RCT_ENABLE_PACKAGER_CONNECTION disabled
      next unless pod_name.start_with?('React')
      target_installation_result.native_target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'RCT_DEV=1'
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'RCT_ENABLE_INSPECTOR=0'
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'ENABLE_PACKAGER_CONNECTION=0'
      end

    end
  end
end

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 37 (4 by maintainers)

Most upvoted comments

I had faced the same issue, but none of the React Native Expert solutions have worked so far - simply frustrated with using RN, i am facing hell of issue building my startup - this is the shittiest language ever developed.

I have the same issue and I deal with it after.

  • remove the app in the Ios simulator (I think this is the main thing for fix this error)
  • run npm start --reset-cache
  • reinstall app with react-native run-ios the problem solved.

I had faced the same issue, but none of the React Native Expert solutions have worked so far - simply frustrated with using RN, i am facing hell of issue building my startup - this is the shittiest language ever developed.

@ahtevus

React Native is not a programming language.

Stay away from expo if you don’t want headaches, just use the bare react native setup, using react-native-cli. I’m also experiencing this issue, but I’m telling the client to ditch expo in favor of the bare react-native cli generated project.

You get that error because the Async Storage from Community has to be linked (either manually or auto-linking).

  • With RN 0.60+, auto linking works for project that did not change any native code (out of the box).
  • If you added Async Storage recently, you need to re-run react-native run-android, to make RN aware of new native module
  • If you’ve changed any Native code (like MainApplication.java) you need to link this package manually.

I have the same error in my andoid project. The version of react native is 0.60.6.I have tried to link ,but failed.Here is my package.json。

{ "name": "ExpenseManager", "version": "1.0.0", "private": true, "scripts": { "start": "react-native start", "test": "jest", "lint": "eslint .", "ios": "node node_modules/react-native/local-cli/cli.js run-ios", "android": "node node_modules/react-native/local-cli/cli.js run-android" }, "dependencies": { "react": "^16.8.6", "react-native": "^0.60.6" } } and here is my application:

`public class CloudpenseApplication extends Application implements ReactApplication {

private static CloudpenseApplication _instance;

public static int[] scrennSize = new int[2];

public static CloudpenseApplication getInstance() {
    return _instance;
}

@Override protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

@Override
public void onCreate() {
    super.onCreate();
    SoLoader.init(this, false);
}

@Override
public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
}

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
        //注意:BuildConfig需要导入自己项目包名下的BuildConfig
        return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new MyReactPackage()
        );

    }
};

}`

  • add this in Podfile : pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
  • cd ios && pod install

I had the same issue, was able to get it working by following this:

@react-native-community/async-storage has been renamed. To upgrade:
- remove @react-native-community/async-storage from package.json
- run "expo install @react-native-async-storage/async-storage"
- update your imports manually, or run "npx expo-codemod sdk41-async-storage './**/*'".

Got it to work! Thank you!

I had the same issue, was able to get it working by following this:

@react-native-community/async-storage has been renamed. To upgrade:
- remove @react-native-community/async-storage from package.json
- run "expo install @react-native-async-storage/async-storage"
- update your imports manually, or run "npx expo-codemod sdk41-async-storage './**/*'".

I’m taking a guess that the author already solved this, but for people searching a solution:

You shouldn’t have to link in react-native >=0.60.
I had the same issue, but it was just that I didn’t run react-native run-android. I compiled in android studio only. Running react-native run-android and then rebuilding in android studio should solve this.

Take a read on this: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md

i gave up and now im using the AsyncStorage of react-native… i have issue before but now its working somehow

On Wed, Apr 22, 2020 at 4:38 AM Donald Wu notifications@github.com wrote:

I’m using expo and I have the same issue too

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/react-native-community/async-storage/issues/304#issuecomment-617484365, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG4P4V6RJTZMKZXW6RHQSWLRNZDBNANCNFSM4KZTQ26A .

delete Podfile.lock and reinstall