What is the link command in npm for?

Asked

Viewed 1,221 times

1

The question is the same as the title: What is the link command in npm for?

Some modules of React Native require the command to be executed npm link react-native-nome-do-modulo

And sometimes some modules stop working when I do that.

What is the real function of this command?

2 answers

3


When you install a third party package in your project you need to point out the dependencies of these

To android, for example, usually these have to be listed in android/app/build.gradle and in android/settings.gradle and indicate the package in android/app/src/main/java/com/<seuprojeto>/MainApplication.java

This is all necessary so that when you assemble the project you can find the necessary files for the operation of that package in your project

But instead of indicating the path manually the command was used npm link ... to apply dependencies automatically

But today this command is no longer used and has been replaced by React-Native link

  • in case, just I type react-native link pacote to make everything okay?

  • and if I use the above command, I no longer need to manually type in the android files?

  • 1

    if you just give react-native link and will search all dependencies

  • 1

    but can give react-native link <nomedopacote> and "link" just this

  • 1

    @Italorodrigo if everything goes right you won’t need to type manually, but sometimes you’ll have to fix some things

  • @Matthew, I’m not in React Active or mobile development, but my answer applies to this case ?

  • @Marcelorafael look at the truth I don’t even know what happens giving today the npm link on a project

Show 2 more comments

0

My environment:

~/pega-usuarios
~/pega-usuarios/index.js       #retorna um array de usuarios
~/pega-usuarios/package.json   #"name":"pega"  #pega será usado para npm link pega.

if I give a npm link within this folder, a global symbology link will be created in {prefix}/lib/node_modules/<package>

Now I’m on my website and I want to get this list of users

~/usuarios
~/usuarios/index.js
~/usuarios/package.json      #

giving a npm link pega, now I have the package pega that’s in the folder ~/pega-usuarios/

Reason why, when you make a change to ~/pega-usuarios will also be done in ~/usuarios/node_modules/pega

Remarks

-When Voce requires a globally linked package, such as the case of pega, It does not go to dependencies in package.json he’s just going to node_modules/

Source
https://docs.npmjs.com/cli/link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.