react-native-async-storage / async-storage

An asynchronous, persistent, key-value storage system for React Native.
https://react-native-async-storage.github.io/async-storage/
MIT License
4.62k stars 459 forks source link

Another NativeModule AsyncStorage is null #985

Closed doneill closed 6 months ago

doneill commented 1 year ago

What happened?

Running an app on Android crashes with

flipper: FlipperClient::addPlugin Fresco
2023-07-06 14:44:44.902  4381-4457  ReactNativeJS           package             E  Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

    To fix this issue try these steps:

      • Run `react-native link @react-native-async-storage/async-storage` in the project root.

      • 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/react-native-async-storage/issues
    , js engine: hermes
2023-07-06 14:44:44.906  4381-4457  ReactNativeJS           package                E  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
          This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
2023-07-06 14:44:44.922  4381-4458  unknown:ReactNative     package               E  Exception in native call
    com.facebook.react.common.JavascriptException: Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

    To fix this issue try these steps:

      • Run `react-native link @react-native-async-storage/async-storage` in the project root.

      • 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/react-native-async-storage/issues
    , js engine: hermes, stack:

Exception in native call
      com.facebook.react.common.JavascriptException: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
            This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

Unhandled SoftException
      java.lang.RuntimeException: Catalyst Instance has already disappeared: requested by FrescoModule

There is no dependency on AsyncStorage in app or app dependencies

Version

N/A

What platforms are you seeing this issue on?

System Information

info Fetching system and libraries information...
System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 261.00 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.3.1 - /var/folders/0q/0szj0ccn1qsggsfyb_3kg2c80000gp/T/yarn--1688680882896-0.5596688192871044/node
    Yarn: 1.22.19 - /var/folders/0q/0szj0ccn1qsggsfyb_3kg2c80000gp/T/yarn--1688680882896-0.5596688192871044/yarn
    npm: 9.6.7 - /opt/homebrew/bin/npm
    Watchman: 2023.07.03.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /Users/dano/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK:
      API Levels: 29, 30, 31, 32, 33
      Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0
      System Images: android-29 | Google APIs ARM 64 v8a, android-29 | Google APIs Intel x86 Atom, android-32 | Google APIs ARM 64 v8a
      Android NDK: Not Found
  IDEs:
    Android Studio: Giraffe 2022.3.1 RC 1 Giraffe 2022.3.1 RC 1
    Xcode: 14.3/14E222b - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.2 - /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.68.5 => 0.68.5
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
✨  Done in 5.67s.

Steps to Reproduce

Hard to say, app has been working for years, all of a sudden this started happening. Occasionally clearing watchman cache with the following allows the app to run but never for long

## mix of steps below occasionally get the app running

## clear watchman
watchman watch-del-all && rm -rf node_modules/ && yarn cache clean && yarn install
yarn start --reset-cache

## clear gradle cache
rm -rf ~/.gradle/caches
rm -rf ~/.android/cache

## clear node/pods
rm -rf node_modules
cd ios && rm -rf Pods/
cd ../ ** yarn
cd ios ** pod install

I am at a loss as it intermittently happens, assuming some change to dev environment caused this or maybe this is a React Native bug, thought I would start here.

FaberGrisalesDev commented 12 months ago

Same promblem with Jest in Unit Test

I have this same problem, only diference is that i have this problem when i'm trying execute the unit test. I'm trying execute a unit test with Jest in react native with typescript template, and the moment start the test, the problem is the next:

app_fingo@0.0.1 test jest Auth.spec.tsx

FAIL src/Test/Auth.spec.tsx ● Test suite failed to run

[@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

  1 | import 'react-native';
> 2 | import '@react-native-async-storage/async-storage';
    | ^

  at Object.<anonymous> (node_modules/@react-native-async-storage/async-storage/lib/commonjs/AsyncStorage.native.ts:23:9)
  at Object.require (node_modules/@react-native-async-storage/async-storage/lib/commonjs/index.ts:1:1)
  at Object.require (setupTests.js:2:1)
  at tryCatch (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:46:17)
  at Generator.<anonymous> (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:127:22)
  at Generator.next (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:71:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:5:24)
  at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:24:9)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total Time: 1.128 s Ran all test suites matching /Auth.spec.tsx/i.

Configuration in setUpTest.js

This is he file the react native reads before execute the test:

import 'react-native';
import '@react-native-async-storage/async-storage';

and de configuration in package.json

"jest": {
   "preset": "react-native",
    "setupFilesAfterEnv": ["./setupTests.js"],
    "transformIgnorePatterns": [
     "/node_modules/(?!react-native-element-dropdown)/"
    ]
 },
"plugins": [
    ["@babel/plugin-proposal-class-properties", { "loose": true }],
   ["@babel/plugin-transform-classes", { "loose": false }]
  ]
krizzu commented 11 months ago

Hey @doneill

There is no dependency on AsyncStorage in app or app dependencies

So probably one your of third-party has dependency on AsyncStorage - meaning you'll have to have AsyncStorage in your package.json, so it's probably linked.

@FaberGrisalesDev Hey, have you checked Jest integration docs?

doneill commented 11 months ago

Thanks @krizzu, I have checked third party dependencies and comes up empty. It doesn't always happen either, but after a bunch of successful runs it returns. A full clearing of Gradle/rn/watchman/pods cache mostly works, but not always, been frustrating

krizzu commented 11 months ago

@doneill Actually, it looks like it's in your tests?

setupTests.js:2:1

doneill commented 11 months ago

That reference is in the comment below, I think the issue is in the hermes stack

If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-async-storage/react-native-async-storage/issues
    , js engine: hermes, stack:

Exception in native call
      com.facebook.react.common.JavascriptException: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
            This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

Unhandled SoftException
      java.lang.RuntimeException: Catalyst Instance has already disappeared: requested by FrescoModule
krizzu commented 11 months ago

I meant this stacktrace log here:

at Object. (node_modules/@react-native-async-storage/async-storage/lib/commonjs/AsyncStorage.native.ts:23:9) at Object.require (node_modules/@react-native-async-storage/async-storage/lib/commonjs/index.ts:1:1) at Object.require (setupTests.js:2:1)

Have you used AsyncStorage before? Maybe some leftovers in jest setup?

FaberGrisalesDev commented 11 months ago

Hi @krizzu, yes i had this in my setUpTest.js

import 'react-native';
import '@react-native-async-storage/async-storage';

And the correct code in this file have to be

jest.mock('@react-native-async-storage/async-storage', () =>
  require('@react-native-async-storage/async-storage/jest/async-storage-mock')
);
doneill commented 11 months ago

@krizzu No references in our app, jest or otherwise

oliviercperrier commented 11 months ago

I also get this when trying to run my app on my expo custom development build.

 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
Shubhankar-1 commented 11 months ago

Hey @doneill I'm facing same issue. in my case it is coming from Firebase. Have you found any solution for it?

github-actions[bot] commented 8 months ago

This issue has been marked as stale due to inactivity. Please respond or otherwise resolve the issue within 7 days or it will be closed.

kimjisena commented 8 months ago

I'm facing the same issue.

github-actions[bot] commented 6 months ago

This issue has been marked as stale due to inactivity. Please respond or otherwise resolve the issue within 7 days or it will be closed.