Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Yarn and NVM Coexist on Windows?

Yarn was working for me until I decided I needed multiple versions of node. So I uninstalled yarn and installed nvm, following instructions from the following guide

I then successfully re-installed yarn using the msi installer. Unfortunately, yarn global add [name] installed packages in a location seemingly spanning all nvm-controlled node versions, and yet equally inaccessible to all of them. That is, npm could not find anything installed globally by yarn. Or, for example, after using yarn to install gulp globally, I find that gulp is not available on the command line (and its cmd files are not found in c:\program files\nodejs).

So I uninstalled the yarn msi. I then re-installed yarn simply with npm i --global yarn, as suggested here. This, at last, caused yarn to be linked to the current nvm controlled node version. Excellent.

However, when I again tried yarn to install global packages I discovered they were not installed properly. For example I ran:

nvm use 5.11.0
yarn global add jspm gulp karma karma-cli

The packages installed successfully, but when I try "gulp" from the command line, it is not available. Also, when I npm ls --global --depth=1 I see that the packages I installed are nowhere to be found. If I try yarn global ls --depth=0 it takes a very long time to tell me that my packages (jspm, gulp, karma, karma-cli) are in fact installed.

Worse, I later decided to do the following:

nvm use 7.3.0    //fresh node install...no packages installed
npm i --global yarn
yarn global ls

The yarn command then shows me the same packages that I installed globally when nvm use 5.11.0 had been in effect. In short, yarn insists on some kind of global install location (separate from what nvm controlled node versions see). I also do not know the file location where yarn is keeping those global packages, so I'm not sure how "clean" of an uninstall I could attempt.

In short, I don't think yarn and nvm are compatible. Is this correct?

Version Info

  • Windows 10 Pro, x64
  • nvm v1.1.3
  • yarn v0.21.3
  • node 5.11.0 (selected by NVM)
  • node 7.8.0 (selected by NVM)

Update

I found issue 1491 might contain my answer. I learned that:

  1. The location of yarn packages installed globally is intentionally in a different location than packages installed globally for npm.
  2. There is indeed a yarn bug which prevents globally installed packages from being available on the command line (doh!). This defeats the purpose of the global install of a package.
  3. The location where Yarn keeps its data on Windows is %LocalAppData%\Yarn

I think the reason yarn was working before I installed nvm, is simply that I had not tried using to install global packages...and thus had not yet noticed the bug. In short, I think it is fine with nvm. However, I now feel I am wasting my time using the npm i --global yarn approach to installing yarn...since yarn will simply put all its global packages into one spot anyway. And, due to the current bug, the only tool I should use for installing global packages is npm itself.

like image 995
Brent Arias Avatar asked Mar 30 '17 04:03

Brent Arias


People also ask

Can we use Yarn in Windows?

Install Yarn on Windows Server via the MSI Installer First, you need to download the Yarn install package. Download the Yarn . msi installer from the official Yarn website.

Can I use NVM on Windows?

Node Version Manager, more commonly called nvm, is the most popular way to install multiple versions of Node. js, but is only available for Mac/Linux and not supported on Windows.

Can I install Node with Yarn?

Homebrew. You can install Yarn through the Homebrew package manager. This will also install Node.js if it is not already installed.


1 Answers

It's a while ago you asked, but I just stepped over your question.

You can simply install yarn as node module globally:

 npm i -g yarn

This works very nicely when using nvm-windows.

Additional hint: Since switching to a new node version with nvm requires to re-install all globally installed node modules, I started to use yarn instead of npm for managing all other global modules except of npm and yarn itself. This way, updating node is quite painless.

like image 94
Peter T. Avatar answered Oct 15 '22 07:10

Peter T.