I have a React Native app that I need to implement external keyboard navigation support
for. I’m trying to install a third party package react-native-a11y
to help with this. However, I already have a local package titled react-native-a11y
that would be a significant amount of work to rename/reconfigure, so I’m attempting to import the new package with an alias react-native-a11y-helper
.
I have something like the following in my package.json
:
"react-native-a11y-alias": "npm:[email protected]",
And after pnpm install, the package is showing up in node_modules with the desired alias as the package name. Then in my code I import a component from the package with no issues at build time:
import { KeyboardFocusView } from 'react-native-a11y-alias';
But the metro bundler throws the following error when I run the app on my Android device
:
error: Error: Unable to resolve module react-native-a11y-helper from <file>.tsx: react-native-a11y-helper could not be found within the project or in these directories:
node_modules
../node_modules
I’ve also tried importing with require
, but no luck.
How can I use this package properly in RN?
2
Answers
As the document of
react-native-a11y
:So you need to follow the install guild carefully:
npm i react-native-a11y
cd ios && pod install
MainActivity.java
:There should not be a situation where there are several identical packages in a project. Recommendation, remove the package that is already installed and install it again (latest version) and make configurations for all cases that are needed. What is the difficulty to leave only one package and work with it?
This package is on GitHub with the necessary instructions, https://github.com/ArturKalach/react-native-a11y