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

What happened?

Just to be clear, I have reviewed every search and article I can find on this topic. I am working on just the Android app to get some underlying issues updated in Android Studio. This is just a relatively simple flashcard-type app.

I have cleaned, rebuilt, and run through every fix I can find.

I’m getting the error: `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`

I followed the above to the letter. I have deleted and added the app back both on the emulator and a physical device. I also created the .apk and ran it on my phone just to make sure it wasn’t a jest issue.

I’ll include the relevant files & commands below, but please let me know if you need more information somewhere:

Version

1.18.1

What platforms are you seeing this issue on?

  • Android
  • iOS
  • macOS
  • Windows
  • web

System Information

System:
    OS: Windows 10 10.0.22621
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i7-1265U
    Memory: 2.74 GB / 15.64 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 9.6.6 - ~\AppData\Roaming\npm\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: AI-222.4459.24.2221.9971841
    Visual Studio: Not Found
  Languages:
    Java: 11.0.19 - C:\Program Files\Amazon Corretto\jdk11.0.19_7\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: Not Found
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to Reproduce

Firstly, I installed the package with NPM: npm install @react-native-async-storage/async-storage

package.json: { "name": "Name", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "@react-native-async-storage/async-storage": "^1.18.1", "deprecated-react-native-prop-types": "^4.1.0", "native-base": "^2.13.12", "react": "18.2.0", "react-native": "0.71.8", "react-native-firebase": "^5.6.0", "react-native-swiper": "^1.6.0" }, "devDependencies": { "babel-jest": "29.5.0", "jest": "29.5.0", "jetifier": "^2.0.0", "metro-react-native-babel-preset": "0.76.5", "react-test-renderer": "18.2.0" }, "jest": { "preset": "react-native", "setupFiles": [ "./jest/jestSetupFile.js" ] } }

^ Just one note on the above, I did try upgrading native-base as well.

Deck.js import React from 'react' import { Platform, Image, Dimensions, TouchableOpacity, View, Animated, StyleSheet } from 'react-native' import { Card, CardItem, Icon, Container, Header, Body, Footer, Left, Right, Content, Title, List, ListItem, Text, Button } from 'native-base' import Swiper from 'react-native-swiper' import firebase from 'react-native-firebase' import AsyncStorage from '@react-native-async-storage/async-storage';

I can provide more code if needed, but when I comment out the above import, the app functions. If I include the import from Native base, I get the removal notification, and if I simply comment out the AsyncStorage, the app otherwise functions with the AsyncStorage functionality.

I ran two different codes in my jestSetupFile, the suggested one here: https://react-native-async-storage.github.io/async-storage/docs/advanced/jest and the current one: jest.mock("@react-native-async-storage/async-storage", () => ({ setItem: jest.fn(() => Promise.resolve()), getItem: jest.fn(() => Promise.resolve()), }));

I also went the mocks_ directory route.

Are there any other suggestions?

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 31 (4 by maintainers)

Most upvoted comments

quit react-native in terminal,then restart with “npm run start --reset-cache”.It works for me!

you could just stop in quit react-native

I face the same problem with Andriod, but it works with iOS. My package.json info below:

"@react-native-async-storage/async-storage": "^1.19.3",
"react": "18.2.0",
"react-native": "0.72.5",

I change the import from import AsyncStorage from ‘@react-native-async-storage/async-storage’ TO import AsyncStorage from ‘@react-native-async-storage/async-storage/jest/async-storage-mock’

😀Working Fine Now Thanx ✌🏻

try that https://github.com/react-native-async-storage/async-storage/issues/994#event-11618552458

kill (remove on backend service) app installed on the simulator before and reinstall the app, and then it works!

Same issue here tried multiple versions can’t make it work.

Im running my app on an expo development build…

win 11 Ract native 0.67.5 node 14 image

I realized the OP did not response yet, so reopening