Yarn: Homebrew should not install node if nvm is already installed

Created on 16 Oct 2016  Β·  35Comments  Β·  Source: yarnpkg/yarn

Attempted brew install yarn and it wanted to install node as a dependency. I already use Homebrew for nvm to manage my npm installs. Since nvm is already installed via Homebrew, the expected behavior is that nodejs installation should be skipped.

Most helpful comment

Developer uses create-react-app.
Developer sees yarn.
Developer goes wtf is yarn.
Developer does Google: yarn.
Developer sees brew install yarn.
Developer runs brew install yarn.
Developer drinks sip of coffee.
Developer sees on screen and finds out Node.js just got installed.
Developer thinks wtf (again), I already had that with nvm!
Developer freaks out having multiple node instances on computer.
Developer does Google: brew install yarn without node.
Developer sees this issue only after the fact (like me).
Developer +1's this comment.
Developer goes wondering how to remove that redundant Node.js instance on computer.

All 35 comments

You should make an issue on the Homebrew repo or fix the yarn formula.

I wonder if the Homebrew formula can check if either node or nvm are installed?

I would like to add tj/n to the list, although we should just check if the node binary is installed and has the minimum required version.

I agree with @billdybas that this really belongs to Homebrew, but I want to chip in anyway as there's a bit more to it.

I think the current scenario is fine, and we shouldn't make it unnecessarily complex – every node version manager is different:

  • What if there are no node versions installed via a manager?
  • What if they are installed but none is set as global?

I've seen dozens of issues where people ran into problems not knowing where their global packages are installed.

I've worked for quite a few companies with very different stacks over the years, and the most bulletproof setup for node I've found is to keep one always up to date version of node for globally installed packages (as we usually want to keep them up to date), and a manager for per-project ones.

I use nodenv (think of rbenv for node, it's pretty much 1:1 code) which I believe isn't as invasive as NVM nor as buggy as n, and flexible enough to let me specify a system node (handled by brew) along with managed per project versions if specified. That way all globally installed packages land in the same place, and can be updated without any issues, migrating etc. It also means that homebrew formulas depending on node work as expected, without adding another node version somewhere else.

TL;DR: Using version managers for global Node.js is an anti-pattern.

the most bulletproof setup for node I've found is to keep one always up to date version of node for globally installed packages (as we usually want to keep them up to date), and a manager for per-project ones.

This sounds reasonable to me!

@designorant I like your philosophy, but let's not get too far from the core issue here, because it's pretty straightforward and simple. If you use homebrew to manage your node env (which many of us do), the two most popular options are node and nvm. Since this is the majority use case, people shouldn't be discouraged to brew install yarn if they went the nvm route because the formula doesn't count for this case.

I feel like this issue should go to the Homebrew repo rather than this repo. The solution should not be specific to Yarn, as it'd affect any app installed via Homebrew that requires Node.js. Ideally Homebrew itself should have some way of allowing apps to specify that they need a "node.js-ish environment", and have both Node.js and nvm fulfill that requirement.

Given that, I'm going to close this issue and kindly suggest that you ask the Homebrew maintainers about it. However, if you disagree with me, please let me know and I'd be more than happy to reopen this issue. Thank you for trying Yarn! πŸ˜„

Not sure if I reported it in the right place, but nonetheless I filed this issue: https://github.com/Homebrew/homebrew-core/issues/6458

Agree with @gillesdemey.
If there's a node binary installed and version check is ok, brew install yarn should not install the node with homebrew again.
And I used brew install yarn --ignore-dependencies installed without node.
But if run brew doctor, will give a warning about missing dependencies.

@cnyyk - @torifat is working on this, as per his comment above πŸ˜„

Thanks for @Daniel15 and @torifat on this issue.
It seems that the changes made by @torifat are not been merged into the main branch of homebrew repo.
I did the installation this morning but still show that dependency not installed.
Shown as below:
`➜ ~ brew info yarn
yarn: stable 0.16.1 (bottled), HEAD
Javascript package manager
https://yarnpkg.com/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/yarn.rb
==> Dependencies
Required: node ✘

➜ ~ brew install yarn
==> Installing dependencies for yarn: node
==> Installing yarn dependency: node
==> Downloading https://homebrew.bintray.com/bottles/node-7.0.0.sierra.bottle.tar.gz
^C
➜ ~ brew install yarn --ignore-dependencies
==> Downloading https://homebrew.bintray.com/bottles/yarn-0.16.1.sierra.bottle.tar.gz
Already downloaded: /Users/YCH/Library/Caches/Homebrew/yarn-0.16.1.sierra.bottle.tar.gz
==> Pouring yarn-0.16.1.sierra.bottle.tar.gz
🍺 /usr/local/Cellar/yarn/0.16.1: 4,257 files, 11.3M
➜ ~ `

Yeah, not merged yet πŸ˜„ You can subscribe to https://github.com/Homebrew/brew/pull/1408 if you like, that way you'll know when it's merged.

@Daniel15 Got it. Thanks.

@Daniel15 this issue also deals with nvm, not just homebrew - how would you recommend nvm users avoid installing an extra node?

How are you installing Yarn?

  • If you're installing through the Windows installer, it doesn't install Node.js
  • If you're installing through the Debian or Ubuntu packages, the Node.js package is marked as "recommended" so you can omit it by passing the --no-install-recommends flag to apt-get install
  • If you're using Homebrew, https://github.com/Homebrew/brew/pull/1408 should cover that

Thanks :-) personally I prefer to install it with npm, but I appreciate you gathering all the advice into one place <3

Installing via npm should work too - That should just use whatever version of Node you're already using.

Note that installing via npm sometimes hits strange edge cases, it's not signed via GPG (same as all other npm packages), and it's significantly slower than any other installation method (that's not too big of a deal if you don't do it often. but I wouldn't do it in a build script for example).

@Daniel15 Is there no way to currently to install yarn via Homebrew w/o installing Node?
I took a look at Homebrew/brew#1408 and looks like activity on getting a fix merged has stagnated?

Not sure, sorry. I don't use a Mac any more so I can't test it myself.

Developer uses create-react-app.
Developer sees yarn.
Developer goes wtf is yarn.
Developer does Google: yarn.
Developer sees brew install yarn.
Developer runs brew install yarn.
Developer drinks sip of coffee.
Developer sees on screen and finds out Node.js just got installed.
Developer thinks wtf (again), I already had that with nvm!
Developer freaks out having multiple node instances on computer.
Developer does Google: brew install yarn without node.
Developer sees this issue only after the fact (like me).
Developer +1's this comment.
Developer goes wondering how to remove that redundant Node.js instance on computer.

Exactly @devotis, x1000. However the folks at homebrew want to sit in their ivory tower on this one and shoot arrows at anyone who raises an alternate perspective: https://github.com/Homebrew/brew/pull/1408#issuecomment-272343833

@devotis

it was mentioned above by @cnyyk but you can do brew install yarn --ignore-dependencies though I don't think its necessary anymore. I've recently set up two new machines and managed to brew install yarn after installing nvm and haven't had any problems yet.

There's now a new flag (like --no-node or --without-node or something like that) for this reason. It's similar to --ignore-dependencies except it will remember it so when you upgrade Yarn it'll also avoid installing Node.js (rather than having to do --ignore-dependencies every time)

For future Google searchers, use following to resolve the issue:

brew install yarn --without-node

Use brew doctor to verify there is no node warning.
NVM now manages your node versions.

For future Google searchers using a Brewfile.

brew 'yarn', args: ['without-node']

Developer runs brew update yarn.
Developer sees on screen and finds out Node.js 11 just got installed.
Developer thinks wtf - I didn't ask for that
Developer does Google: brew install yarn without node.
Developer sees this issue only after the fact
Developer +1's this comment.
Developer goes wondering if he should try nvm this time

Developer +1's this comment
Developer proceeds to remove Node 11 and replace with Node 10, this time trying nvm
Developer curses ivory arrows for not preferring LTS versions of Node by default
Developer installs nvm this time in the futile hope he'll not be back +1'ing this comment
(Developer edit's comment, not being a react user but an aurelia devotee)

Was there a regression or change here? The official yarn docs call out the above flag, but running brew install yarn --without-node on a brand new environment is installing node as a dependency.

@jaygorrell The Homebrew team changed that, and they appear to be locking any conversations about it, disallowing people from even talking about it:

There's a discussion about it in https://github.com/yarnpkg/yarn/issues/6946. It sounds like we can create our own "tap" to re-add the --without-node option.

Ah, thank you!

Yeah it's pretty annoying... Yarn is the fifth most popular package on Homebrew (ref https://formulae.brew.sh/analytics/install-on-request/365d/) yet they didn't inform us of this change at all.

Considering the number of people who need to install yarn without node, it might be time to reconsider recommending brew as the official method. Maybe the [alternative] method should be the One True Way.

[bash] npm install --global yarn
FTW πŸ’ͺ

From what I could gather in all of the related threads/topics, the homebrew preference is to correctly set your PATH to use the binaries you want, which makes sense.

With that in mind, I've opened an issue (https://github.com/Homebrew/brew/issues/6129) to suggest that brew's depends_on will similarly look at binaries available on PATH when considering whether it needs to install a new formulae.

This would seem to solve everyones needs in a pretty effective/non-hacky way IMO.

Was this page helpful?
0 / 5 - 0 ratings