I am trying to run my react native project In my IOS device. I start my server with npx react-native start then I start my app with Xcode. And I get this error:
error: Error: Unable to resolve module @react-native-community/async-storage from /Users/nicolelopez/dev/LeksPlay/src/Core/onboarding/utils/AuthDeviceStorage.js: @react-native-community/async-storage could not be found within the project or in these directories:
node_modules
../../node_modules
If you are sure the module exists, try these steps:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
> 1 | import AsyncStorage from '@react-native-community/async-storage'
| ^
2 |
3 | const SHOULD_SHOW_ONBOARDING_FLOW = 'SHOULD_SHOW_ONBOARDING_FLOW'
what I have tried:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
i have deleted node_modules and my package.lock.json and have re-installed yarn and done a pod install.
i have tried to restart the computer
i have tried to do a yarn add @react-native-community/async-storage
i am running on node 14 - because I have run in to similar issues with a higher version of node.
i am running Xcode in Rosetta mode - since I am on a Mac M1.
i have tried to change my AsyncStorage import to import AsyncStorage from '@react-native-async-storage/async-storage';
I have also tried to add pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
but they all result in the same issue - with is the error code I posted. It gets no different no matter what I try. I am really new to react native, this may be a common issue but I can't seem to find anything that helps.
You should use the proper package called @react-native-async-storage/async-storage.
The one you are using is deprecated, check it out on : https://www.npmjs.com/package/@react-native-community/async-storage
Having the two will lead to issues.
If the issue still persist, try to clear all the cached, there is a good tool that will help you clean your react native project: https://github.com/taboulot/rn-game-over
npx rn-game-over --all
If you still have the issue afterward, please update your question with the new detail.
From the usage documentation, it looks like you're importing Async Storage incorrectly. You should be importing from @react-native-async-storage and not from @react-native-community. Further, you seem to be confusing the two packages. Ensure you've completed the relevant installation steps as well.
To install the correct package:
yarn add @react-native-async-storage/async-storage
And to import Async Storage:
import AsyncStorage from '@react-native-async-storage/async-storage';
as written in the documentation, it's not using @react-native-comunity. It means you should install the react-native-async-storage with :
npm install @react-native-async-storage/async-storage
or
yarn add @react-native-async-storage/async-storage
and not
npm install @react-native-community/async-storage
and if you got an issue or error while using the package, here's the code I tried on my project to solve the problem:
rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-* && watchman watch-del-all && yarn cache clean --force && rm -rf ios/build && rm -rf node_modules/
i got the solution from here https://stackoverflow.com/a/67865721/8367675