2
votes

I have been trying to include a React native library (Local Library) to the React Native app.

So I installed it using

npm install library-path

Then I run

npm link libraryname

I can see the package in the node_modules of the mainProject. Also, in package.json, I can see the dependencies:

"dependencies": {
    "react": "16.13.1",
    "react-native": "0.63.2",
    "react-native-first-library": "file:../react-native-first-library",
    "react-native-toast-message": "^1.3.3",
    "react-native-webview": "^10.8.3"
  },

react-native-first-library is my react module.

I have done

  1. Clear watchman watches: watchman watch-del-all
  2. Delete node_modules: rm -rf node_modules and run yarn install
  3. Reset Metro's cache: yarn start --reset-cache
  4. Remove the cache: rm -rf /tmp/metro-*

But still, it is not working. I don't know why these things are so complex.

2
If you remove this given library that works? Can you provide more info on that one? Also, make sure you removed yarn.lock file or package-lock.json before reinstalling node_modules. - David Thery
I just copy-pasted the "created Local Library" into the "node_modules" and it worked. I figured out after a long time. Thanks David. However, there is another problem, if you can help, I want to create a react native library which will have a webview and certain parameters must be passed from the react native app, like url and some other data and give the callbacks back to the project. If you know a way to do this. Please let me know. Till now i have made a component and render it in the app. - Aman Verma
This post might answer it (however I'm not sure this is the good place to broach another topic): stackoverflow.com/questions/62902660/… - David Thery

2 Answers

0
votes

I had to integrate a custom library once. I just created a folder at root level customLibs and I put the folder of my library into. Then in the package.json I specified "myLib": "file:./customLibs/myLib"

I'm not sure but in your package.json the path should not be file:../react-native-first-library with two dots but surely with one dot.

And at the end just yarn or npm i

0
votes

just do one thing

1). copy the local library folder and paste it into the node_modules of the react native project..

example =>

i have a library say react-native-test

=> after installing it in a react native project I can see that package.json file has added a dependency like "react-native-test": "file:../react-native-test",

but i got an error as soon as I ran the project displaying unable to resolve module

=> just copy the react-native-test folder and paste it into the react native project's node_modules folder and do npm install again