I have a react native module, where i would like to use a common module for a minor thing, but i don't want to force someone to include it just for this.
So i want to check if the module exists, if thats the case use it, if not do a workaround. Code could look something like this:
import Module from 'react-native-non-existing-module'
if (Module) {
// do something with the Module
} else {
// use fallback
}
But i then get an error:
Error: undefined Unable to resolve module
react-native-non-existing-modulefromsrc/myFile.tsx: react-native-non-existing-module could not be found within the project.If you are sure the module exists, try these steps:
- Clear watchman watches: watchman watch-del-all
- Delete node_modules: rm -rf node_modules and run yarn install
- Reset Metro's cache: yarn start --reset-cache
- Remove the cache: rm -rf /tmp/metro-*
I also tried this:
How to check in node if module exists and if exists to load?
But that didn't work for me either