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

I am developing a ui button pack for a native reaction. I am trying to create a sample project to test this button. The directory structure is as follows:

my-button/
    package.json
    index.js
    example/
        package.json
        index.js

I am trying to use npm link:

cd my-button
npm link

cd example
npm link my-button

In example/node_modules/I see a symbolic link to my button, VSCode can also automatically exit in the button package.

But in the sample application example, an error message appears:

Unable to resolve module my-button ...
Module does not exist in the module map or in these directories: ...

But the path in the error message is correct.

Not sure where I was wrong, or React-Native has any special way to handle the local link dependency?

I also tried npm install file:../.. This way it works great, but it's not easy to update the dependency in example/after I edited my button.

+6
5

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

npm link,

# 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
+2

npm link , React Native packager .

, .

Haul, , storybook, , .

+1

. npm link , , ,

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

This will install the package as a regular package, but from a local folder. The disadvantage is that the changes you make to the package will not be reflected. After each change you will need npm install.

0
source

Try to run

npm run watch

inside the button pack. I am currently using this to apply changes from the library to my main project. Please let me know if this works!

0
source

Change your .json package

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

Source: https://habr.com/ru/post/1017377/


All Articles