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

大城市里の小女人 提交于 2019-11-29 21:24:59

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.

Try wml (https://github.com/wix/wml)

It's an alternative to npm link that actually copies changed files from source to destination folders

# add the link to wml using `wml add <src> <dest>`
wml add ~/my-package ~/main-project/node_modules/my-package

# start watching all links added
wml start

Ran into the same problem. While I could not make npm link work as it should, I worked around it by installing the local package in the project folder

npm install ../<package-folder> --save

This will install the package like a regular package but from the local folder. The downside is that the changes you make on the package will not be reflected. You will have to npm install after every change.

Change your package.json

//...
"dependencies": {
   //...
    "my-button" : "file:../"
  },
//...

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!