'ERROR Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null

I am creating a React Native iOS app, NOT using Expo. I installed AsyncStorage @react-native-async-storage/async-storage and am using it in my app as illustrated in the code below.

The problem is that I am getting the below error message. I have tried to fix the problem by taking the following steps, however the error persists. Can anyone advise how to fix the error?

My code:

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

const authenticate = (token) => {
    setAuthToken(token)
    AsyncStorage.setItem('token', token)
}

Steps I've taken to resolve error (all unsuccessful):

  1. quit the terminal and simulator, then rebuilt and restarted app
  2. ran npm start --reset-cache
  3. navigated to ios directory and ran pod install

The error message:

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


Solution 1:[1]

This error usually occurs when the library was not linked correctly or if auto-linking is not working. Try linking the library manually as explained here.

react-native link @react-native-async-storage/async-storage

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sushrut619