Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a npm library created for react-native without publishing to npm

I created a npm libary using react-native-create-library. I can publish the newly created library into npm. But as I developing, I'm not able to test it locally with a react-native project.

If I tried to add by adding the file path to dependancy section of package.json then I'm getting this error

error: bundling failed: Error: Unable to resolve module react-native-test-library-abcd-one from C:\Users\kk\TestLibABCD1\LibraryTester\App.js: Module react-native-test-library-abcd-one does not exist in the Haste module map

It will work if I do a npm install react-native-test-library-abcd-one.

How can I link my local libaray in this case?

like image 846
krishnakumarcn Avatar asked Oct 23 '25 06:10

krishnakumarcn


1 Answers

You should use the git clone url set against the library name in your package.json.

Thats how incrementally the bigger softwares/libraries are developed You should versionize it using git or something else. :)

That should look like:

"react-native-touch-id": "https://github.com/surajj2223/react-native-touch-id.git"

If that would not have been your library then a simple use case where such thing is needed: You alter some code as per your need in some specific library so you have your own version of the library now and upon next npm install/yarn install you lose your changes if you have not uploaded that on git. So what can be done is,

  1. Fork the original library.
  2. Clone it and make changes to it and push it.
  3. Now use your library's clone url against the library name in your package.json
  4. npm install/yarn install and you are good to go now.

And if you make some really generic changes that others would also be needing then its always better to make a pull request to the original library and get it merged thereby helping the community too.

like image 171
Suraj Malviya Avatar answered Oct 25 '25 23:10

Suraj Malviya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!