I want to create react-native module for iOS and Android and use it in an application.
I want to use it like a local module, not uploaded to npm.
When i follow the steps described in the official documentation i always have those error on the import of my module into App.js file :
import MyModule from 'react-test-module';
Could not find a declaration file for module 'react-test-module'. '/Users/dbellerose/Path/to/My/Module/react-test-module/index.js' implicitly has an 'any' type. Try npm install @types/react-test-modulet
if it exists or add a new declaration (.d.ts) file containing `declare module 'react-test-module';
When i run the iOS application :
Unable to resolve module react-test-module
from /Users/Path/To/My/App/App.js
: Module react-test-module
does not exist in the Haste module map.
The message give me some tips to solve the problem, but it does not work.
To resolve try the following: 1. Clear watchman watches: watchman watch-del-all
. 2. Delete the node_modules
folder: rm -rf node_modules && npm install
. 3. Reset Metro Bundler cache: rm -rf /tmp/metro-bundler-cache-*
or npm start -- --reset-cache
. 4. Remove haste cache: rm -rf /tmp/haste-map-react-native-packager-*
.
So what do you know what is the good process to create a module and use it in application without uploading the package to npm ?
Best regards,
David
Here's some steps I could share with you as a checklist:
yarn global add create-react-native-module
create-react-native-module MyLibrary
yarn install
To link to your project, you will need to add the following to your package.json (the path should be wherever your module is sitting at)
"react-native-test-module": "file:../",
"react-native-my-library": "file:../../react-native-my-library/"
** Do keep in mind, if you have new methods appended in module. You will need to:
yarn/npm install
& pod install
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.