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)
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.
npm start --reset-cache
react-native run-ios
the problem solved.@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, usingreact-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).
react-native run-android
, to make RN aware of new native moduleMainApplication.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 {
}`
pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
Got it to work! Thank you!
I had the same issue, was able to get it working by following this:
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. Runningreact-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:
delete Podfile.lock and reinstall