-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null. #89
Comments
Looks like you forgot to re-compile your app with Let me know if that helped. thanks. |
what do I do if i use expo-cli, im facing the same issue. (i'm new too) |
If you're using |
okay thank you for the replies, but asyncStorage will be removed from react native? or i can continue using it ("forever")? |
@IvanFMt It will be available, no worries. It's just a transition from Core repo to Community packages. Going to close thread for now, let me know if you need to re-open it. |
thank you. Have a good day |
Hi @krizzu |
What's the output of Then, remove the app from emulator/phone and reinstall via |
I'm having the same issue on Android (both emulator and physical hardware). I have tried:
I don't have any code that's using AsyncStorage yet. The only line I've added between the last working version of the app, and the one with this message, is I think I've tried everything the error message suggested (unless, based on my descriptions above, you can see that I've misunderstood something?). Any ideas? |
@rahimnathwani Hey, Can you check if your @mikeislearning Right, Can you confirm that everything is linked correctly (you can check manual linking to confirm correctness). thanks. |
@krizzu Yes. Here the relevant lines from
I've copy-pasted the above directly from my code, and it appears to be the same as in the docs. Does the import order matter?
|
I had modified the MainApplication per the react-native-navigation, and that seems to have confused the linking. Adding them manually made it work. |
Can you guys provide a separate repo with same setup you have, so I could have into it? thanks. |
After installation make sure to run |
@krizzu thanks. I sent you an invitation to the private repo where I faced this issue. The branch 'community-async' is a snapshot of the time when I was successfully using AsyncStorage from core. To reproduce the error, check out that branch, and change these two imports to from core to RNC:
I am not longer using AsyncStorage directly. Instead I switched to redux-persist, which uses AsyncStorage under the hood, and I will probably also use redux-persist for my next RN project. FYI - There's an open issue there suggesting redux-persist hasn't migrated to the RNC version yet. |
@rahimnathwani I've made an issue in your repo, telling what to do. Basically the problem was using Wix's navigation and not following their install instructions. You ended up with two |
I am still facing same issue 'NativeModule: AsyncStorage is null'. I tried everything, I have added react-native-navigation and react-native-vector-icons, Is this the problem?. Please suggest something as I am stuck, any help is appreciated. |
I assume you have run |
@krizzu Thanks so much for looking into this, and for the detailed instructions. I understand what is wrong now, and how to fix it. FYI - I just checked the commit where I implemented the installation instructions from wix/react-native-navigation, and the diff for MainActivity is the same as in the web page you linked, except for an extra closing brace[0]: https://github.com/rahimnathwani/monica-companion/commit/7dcb1896b95c1823f6d0f90e5270772a412383f1#diff-44d72f20b3ff8b741d2664683bb93abd [0] I assumed this was a typo on their page, as if I include it, then the number of closing braces added by the diff is larger than the number of opening braces, which cannot be right. |
@krizzu yes i did run react-native link. Here is my MainApplication.java file. package com.rntestapp;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;
import com.oblador.vectoricons.VectorIconsPackage;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends NavigationApplication {
@Override
protected ReactGateway createReactGateway() {
ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
@Override
protected String getJSMainModuleName() {
return "index";
}
};
return new ReactGateway(this, isDebug(), host);
}
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
protected List<ReactPackage> getPackages() {
// Add additional packages you require here
// No need to add RnnPackage and MainReactPackage
return Arrays.<ReactPackage>asList(
// eg. new VectorIconsPackage()
);
}
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return getPackages();
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new AsyncStoragePackage(),
new VectorIconsPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
} |
@nairabhijit Same situation. You have two |
Thanks a lot @krizzu , this resolved the issue. |
No response, but I still get this error in the simulator. |
https://github.com/QuantumProductions/dirt/tree/tokens from project directory
|
react-native link dosen't add import AsyncStoragePackage to MainApplication... should be done manually |
@quantumpotato You won't get this lib running with expo, as expo does not allow to extend its native module packages. @yhmin84 If it's the issue, I'd create an new issue on RN-CLI repo |
I'm having this issue when I upgrade the storage of redux-persist See issue here https://github.com/rt2zz/redux-persist/ But when I use
I got error saying [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null. |
@stacywang0601 Yes, you have to link this package in order to use it. You can do so by using |
platform :ios, '9.0' |
Guys. If you also suffer from this bug - you can try:
and then
|
If you're using pods, adding this to my Podfile fixed this issue: |
I'm using RN 0.60 and throws this error, isn't supposed to be autolinking? it isn't for me somehow, because it throws that error. |
I'm having this issuee. But I solved running pod install in ios folder because react native 0.60 has Podfile by default and they add |
@m4rcoperuano hi guys, thanks a lot If you're using pods, adding this to my Podfile fixed this issue: |
I fixed the issue on Android by checking the Depending on which branch of https://github.com/react-native-community/async-storage is active you can find the documentation at the following path, https://github.com/react-native-community/async-storage > docs > Linking.md.
After updating/linking the file manually Android started working. |
I am using expo and facing the same null problem for asyncstorage. I installed and linked |
@priyajainSE You can't add new native modules with Expo, so this package won't work for ya. |
I was getting this problem in the app but manual linking fixed it, but now it is null in my jest unit tests. I can mock it of course but it is extremely worrying if it is there sometimes and not others. Has anyone else found this? RN: 0.59.10 |
I mocked the module as would need to anyway, but it still worries me that it is inexplicably null during testing... |
问题解决方案 |
In my case the automatic linking did not add any line into the MainApplication.java file. I had to manually type the import and the corresponding package in the getPackages() method, just as it is explained in point 3 (Android) at: https://github.com/react-native-community/async-storage/blob/LEGACY/docs/Linking.md You have to rebuild the project again with |
@alcristog auto-linking is not adding any line in your |
I was also facing this issue on iOS, after reading the instructions carefully, it says you can do Did that and rebuild the app, its working fine 😄 |
In my case. I'm using 'Expo'. This is my code. import { createStore, applyMiddleware } from 'redux';
import { dishes } from './dishes'
import { comments } from './comments';
import { leaders } from './leaders';
import { promotions } from './promotions';
import { favorites } from './favorites';
import { persistStore, persistCombineReducers } from 'redux-persist';
import thunk from 'redux-thunk';
import logger from 'redux-logger';
import { AsyncStorage } from 'react-native';
export const ConfigureStore = () => {
const config = {
key: 'root',
storage: AsyncStorage,
whitelist: [
'favorites'
]
};
const store = createStore(
persistCombineReducers(config, {
dishes,
comments,
leaders,
promotions,
favorites
}),
applyMiddleware(thunk, logger)
);
const persistor = persistStore(store);
return { persistor, store };
}; |
Why is this issue closed? It is still happening. 🙂 Autolinking doesn't work and even worse |
@developer239 If auto-linking is not working for you, I'd suggest to check out docs about how it works and what setup you have to have in order to get it working. Most devs have problem after upgrading from <=0.59 to 0.60+. This is because there are changes to native code that need to be addressed in order to get auto linking work. |
It's maddening, it was working fine and apparently this error just came up:
|
You Resolved it? |
I had this issue for a very brief moment but if someone else if having the same here is some info.
I ran After that everything was fine. |
The same issue with Android. |
This comment has been minimized.
This comment has been minimized.
@BrandedNomad: I've hidden your comment because it's just plain wrong. Reverting to AsyncStorage in If you're still hitting this issue, please file a new issue with your environment information and a repro so we can help you debug this properly. |
Hello Guys, am new to react native i just facing a new problem which i cannot understand what and why its happening ? any one help me with this,
I was just try to use AsyncStorage for local storage and its just working fine when i import the AsyncStorage from react-native like :
import { AsyncStorage } from 'react-native'; (its working fine )
But when i try to use by import the AsyncStorage from @react-native-community/async-storage
like :
import AsyncStorage from '@react-native-community/async-storage';
it produce error like :
[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.
To fix this issue try these steps:
• Run
react-native link @react-native-community/async-storage
in the project root.• Rebuild and restart the app.
• Run the packager with
--clearCache
flag.• If you are using CocoaPods on iOS, run
pod install
in theios
directory and then rebuild and re-run the app.Why it is Happning with this import ? and I forget to tell that I also run the link command as
The text was updated successfully, but these errors were encountered: