React Native: npm link local dependency, unable to resolve module

后端 未结 8 1374
不知归路
不知归路 2020-12-23 02:14

I am developing a button ui package for react native. I try to build an example project to test this button. The directory structure is as follows:

my-button         


        
相关标签:
8条回答
  • 2020-12-23 02:45

    Try to run

    npm run watch
    

    inside the button package. Currently, I'm using this to apply changes from the library to my main project. Please let me know if it works!

    0 讨论(0)
  • 2020-12-23 02:46

    The npm link command doesn't work because React Native packager doesn't support symlinks.

    After a little research, I discovered that there are two ways to go about it.

    1. Use haul packager in the example app. Haul supports symlinks, so you can use npm link as usual.
    2. Use local dependency via file:../ and then edit files in node_modules folder or reinstall every time you make changes.

    I found Haul to work great for this use-case and even set-up a little starter project that also includes storybook, which is really helpful if you have many components to switch between.

    0 讨论(0)
提交回复
热议问题