async-storage: NativeModule: AsyncStorage is null
What happened?
Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.
To fix this issue try these steps:
• Rebuild and restart the app.
• Run the packager with --reset-cache
flag.
• If you are using CocoaPods on iOS, run pod install
in the ios
directory and then rebuild and re-run the app.
• If this happens while testing with Jest, check out docs how to integrate AsyncStorage with it: https://react-native-async-storage.github.io/async-storage/docs/advanced/jest
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-async-storage/async-storage/issues LOG [TypeError: undefined is not an object (evaluating ‘_$$_REQUIRE(_dependencyMap[13], “…/…/utils/AsyncStorage/asyncstore”).setItem’)]
Version
1.16.1
What platforms are you seeing this issue on?
- Android
- iOS
- macOS
- Windows
- web
System Information
OS: macOS 11.2.3
CPU: (8) arm64 Apple M1
Memory: 822.64 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Steps to Reproduce
When I try to setItem it returns me this error always.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 18
- Comments: 25 (4 by maintainers)
The most common issue with
AsyncStorage is null
is because the app was not rebuild after installing the library. And I don’t mean to restart bundler, but rather install an app on the device/simulator. So best way to handle this is:Same error here. I am experiencing it on an Android simulator and I didn’t do any tests so far, just imported the dependency, saved it, and the error popped out on my screen. I am using version
1.17.7
for the async storage, and0.68.2
for RN.Exact same issue, I’m not sure what else to try.
In the browser console the object is defined, but in the terminal I get
Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.
I’ve tried all the suggestions, including rebuilding npm, pod update, manually linking etcHi guys, same issue, but I remember that before had the error of this issue, I was stuck on the import error on the react-native code something like
unable to resolve module
at lineimport AsyncStorage from '@react-native-async-storage/async-storage';
. Then I just power-off my PC and when I relaunched all the stuff:I got from Metro:
Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.
I resolve this issue following these steps:
npm instal --reset-cache
(i need to use --force too, so->npm instal --reset-cache --force
)cd ios
pod install
cd ..
npx react-native start
npx react-native run-ios
npx react-native run-android
Now it is working for me.
Main project info:
node version: v18.8.0
I am experiencing this issue now as well. Did anyone succeed to resolve it?
I’m also experiencing this issue on Android release variant. Anyone have any idea about this? It’s pretty fine working on my other apps and this app but on debug mode, but somehow not in my current app in release mode. In emulator, and on other device. Still don’t know how. Already following any suggestions but got no result.
Even, the module is exists on android studio.
We’ve had the same issue when upgrading from React Native 0.63 -> 0.64
It seems like the React Native NativeModule structure has changed with this release. And something (perhaps related to Native Modules?) seems to have stopped our async storage mock working.
Async storage mock at
__mocks__/@react-native-async-storage/async-storage.js
:React Native mock:
I’m running a very simple test that should use the mock :
i’ve correctly installed and built the library and the app is working fine in the simulator, so it just seems like the mock isn’t being applied (or is overwritten) for some reason.
Has anyone found any solutions/workarounds? Or anything I can try to debug?
I’ve been on this since yesterday and i’ve installed, reinstalled, uninstalled a few versions of my app several times. But there is a slim chance that i never reinstalled it right after installing async storage. Will try that next and get back at you. Thanks
I solved this error, thanks Chat gpt, you have to do the following:
cd android && ./gradlew clean && cd ..
2.In MainApplication.java
Add this line:
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
and after:
add newAsyncStoragePackage(),
And run your app again.
This is the correct solution. I had this problem with both Expo Go and custom dev client. I was able to get both working successfully by reinstalling them manually on my mobile phone.
I am not sure why this is required, or why reinstalling fixes the issue though. Hope someone can provide an explanation.