Cli: Make package name required for "link"

Created on 15 Dec 2018  Â·  47Comments  Â·  Source: react-native-community/cli

When you don't pass a package name to the "react-native link", it will try to look for all packages to link from your node_modules.

This is causing us a lot of issues, such as linking wrong packages or the ones that someone doesn't want to link (e.g. decided to use a different way of linking that is out of scope for this command).

We should simply stick to requiring package name.

backlog link

Most helpful comment

I use for custom fonts!

All 47 comments

Please leave a comment if you are using react-native link to link your project assets and describe your use case. This behaviour will be also deprecated since the name of the package is going to be required.

I would like to be able to link my assets to iOS and Android projects.
I can do it with RN 0.57.8, but I cannot with RN 0.59.x
link_assets1
link_assets

Yup. We plan to introduce a new command or flag that will link only project assets. For now, you should be able to link project assets with react-native link, but it is deprecated.

thanks @Esemesek

currently it's not possible to link root assets with RN 59 rc2.

I've changed () => linkAssets(platforms, project, assets) to () => linkAssets(platforms, project, { assets }), in linkAll
and it worked, but I'm not sure if it's proper fix.

@sijad This is a bug. linkAll should link root assets. I'll fix that in a minute.

I use it to link my font assets

@kennetpostigo in the future there will be a separate command to link project assets.

I think that when "react-native link" is entered, it must ask if the user really wants to link all libraries. This way, it will be better for the people who installed more than one library and wants to link all of them, or if the user is new to React Native, this will be easier for him/her.

We have react-native link setup in our PostInstall script so that when we update our dependencies any changes to the linking instructions get applied correctly.

We do not have Cocoapods, so we don't want there to be dependencies that are partially linked.

If the API changes so we have to enumerate all the packages we want linked, then what I would do is figure out the list of packages, and then make our post install script iterate over every entry in that array to link them one at a time. -- This is a minor annoyance, but no big deal.

I use for custom fonts!

I use postlink hooks in a couple of "helper" packages (e.g. react-native-pod) to update native considerations based on the current state of the app directory (e.g. after modifying app-level package.json). This allows for dry code and a lot of leverage from link. Will there be hooks to allow other packages to listen for per-package link events, like a postotherlink (with a better name)?

Or is this a PR/Issue that should be discussed under separate cover?

@rhdeck please create a new issue as it's not related to this one :)

I use it when making quick poc or tests. For this kind of situation there's never that much of trouble. And it's quite convenient.

Maybe making it optional with a warning?

That's not too much of a hassle to type it whith every package name anyway. So no big deal.

i use it to add dependencies after npm install react-native-webview

if you add several dependencies at once and just want to link them all or update, it is much easier to use react-native link without package name. The command has the option to use a package-name if this is not want you want, so why deprecating or removing the other option?

Like mentioned before, fonts.

I definitely only ever use 'react-native link' as my one and only go-to command to make sure that all my dependencies are linked. If you want to link a specific package, you already can. Maybe a new setting in the CLI could be added to lock this functionality from people who are worried about doing it accidentally; something like 'react-native set strict-link' perhaps, or maybe a command for unlocking it instead.

P.S. Why encourage non-standard methods of linking anyway? Why not double down on your standard, or expand functionality to fit the shortcomings people needed in these other linking methods then?

Maybe having a react-native link assets command so we could link fonts would be good?

I use just to link my custom fonts, as mentioned before

Maybe having a react-native link assets command so we could link fonts would be good?

And what will happen when one installs a package named "assets"? boom

Maybe let link without arguments link assets by default, and simply stop linking all other things. That seems most sensual to me

Sensible*... Phones.

If you look closely into the PR (https://github.com/react-native-community/react-native-cli/pull/101) it already introduces link-assets command.

@vandervidi it was just an example. I agree that link-assets is better.

I did link all because I needed to reset my project since I'm upgrading from a somewhat old version.

agree with @sm1th
link-assets is a better option

It shouldn't be deprecated. The current commands are better. Those who want to to link any specific packages can link individually, while others could do it all at once with a single command.

Why to deprecate? We have the option if someone want to link particular package then he/she can do that also.
If you have 30 libraries and you want to link them all in one go then you can do it with react-native link and if you want specific then you can do that also, then what is the need of removal?????

For Assets i feel there should be option, if someone only want to link assets.

We decided not to introduce this change because the link command will be deprecated soon in favor of autolinking feature. Right now we are working on it, and it should be available in 0.60.0.

I use it because some things need to be linked but I never really know what

When you have a react native project and have to migrate to a new installation one run react-native link to link all dependencies, imagine if you have to linked them all manually, or when you want to copy bunch of package from an old package.json to a new package.json and some of them need to be linked, react-native link is a great tool

for a most of my new react native project i add a bunch of dependency which is some of that require to linking after that i just one time use react native link and it resolve all native issues.

expect that we are linking custom font with react native link. how can be link custom font with package name ??

如果移除了,那么 react-native-template 项目怎么办

@Esemesek what's the path moving forward for autolinking?
I'm having linking issues with local fonts, could be a race condition in 0.59.8.

I get a lot of, changes font file names listed on every run

debug Error: EBUSY: resource busy or locked, unlink

I double checked, 0.59.X and higher give me race conditions when linking on Windows.
0.58.X has the pathing bug on windows that causes Windows paths (\) to be linked.

@skhameneh whole you're investigating that, would you mind sending a PR with a fix? We don't use Windows for development unfortunately and that would much appreciated

@thymikee I don't have a fix at the moment.
I found killing adb.exe releases some of the file locks on my fonts.

Here's some extra info for possible repro:

$ adb --version
Android Debug Bridge version 1.0.41
Version 28.0.3-5475833
$ react-native --version
react-native-cli: 2.0.1
react-native: 0.59.8

react-native link doesn't link fonts for now.
react-native: 0.59.8

@justynasowinska can you share a minimal repro so we can investigate what's the issue?

i am trying to use this to link fonts. but unfortunate its not working as posted 2 days ago. need alternative. :(

Used this because of example on this page: https://www.npmjs.com/package/react-native-fetch-blob

I use this command to link my fonts.
Everything else I link manually.

I created a new project with updated react-native version and at once I added all of the project dependencies. in this case, react-native link command were useful.

I use it to link custom fonts

I use link if I forgot about the package name, and to linking fonts and my custom styles.

Thanks for all the input, it's really valuable. As @Esemesek already noted here, we're not gonna introduce this change.

Since React Native 0.60, we hope the need for react-native link will massively drop because of the autolinking feature, which we hope you'll love. However, we don't deprecate it just yet. In fact, we're changing the default behavior to only link assets, as this is what majority of us use the link command without package name for. If for any reason you'd like to link all assets and native modules, the --all flag was introduced to facilitate that.

So to recap:

  • react-native link -> will link only assets since RN 0.60
  • react-native link --all -> will work exactly the same as react-native link befre RN 0.60
Was this page helpful?
0 / 5 - 0 ratings