Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a list of many global packages with Yarn

yarn install -h suggests that the -g (global) option is DEPRECATED. How am I supposed to indicate that I want a bunch of packages (from package.json / yarn.lock files) to be installed globally?

Options I saw:

  • yarn global [command] has things such as ls and add but not install. add only works with particular package names, if I understand correctly. I already have my yarn.lock file ready, I don't want to repeat myself on the command line.
  • yarn global add each package one by one. Now my list of packages would be imperative instead of declarative.

Specifically, I'd like to use one executable from one of those packages.

like image 846
jleeothon Avatar asked May 10 '17 14:05

jleeothon


People also ask

How do I install multiple yarn packs?

Using npm install npm install all the packages in the package. json . But it looks like you need to specify each package when using yarn add according to https://yarnpkg.com/en/docs/cli/add. yarn add package-name installs the “latest” version of the package.

Can yarn install all npm packages?

The Yarn maintainers recommend installing Yarn globally by using the NPM package manager, which is included by default with all Node. js installations.


2 Answers

Simply type

yarn global add nodejs 
like image 144
vijay Avatar answered Oct 01 '22 00:10

vijay


How am I supposed to indicate that I want a bunch of packages (from package.json / yarn.lock files) to be installed globally?

You shouldn't. Installing globally is discouraged by Yarn, and there are very few situations where it's necessary, or even helpful.

As noted in the documentation:

For the vast majority of packages it is considered a bad practice to have global dependencies because they are implicit. It is much better to add all of your dependencies locally so that they are explicit and anyone else using your project gets the same set of dependencies.

If you are trying to use a CLI tool that has a bin you can access these in your ./node_modules/.bin directory.

But I really, really want to!

If you really don't want to listen to the advice given, use

yarn global add <package> 

However, don't expect to easily install a huge list of dependencies globally—it's hard to do by design, because it's not a good idea.


Instead, the intended flow with Yarn is:

  • install everything locally, so each project is isolated
  • call binaries from ./node_modules/.bin where possible
  • avoid global installs—they're a convenience, but not one you should rely on.
like image 40
Aurora0001 Avatar answered Oct 01 '22 01:10

Aurora0001