{ sung.codes }

by dance2die
🌞
Blog
← Go Back

'yarn global add' command does not work on Windows

Broken Post?Let me know

Featured Image -Photo by Olliss on Unsplash

When you install a new global NPM binary using yarn on Windows machine, you run into the situation where the installed binary is not found.

I will show you how to resolve that issue.

Problem

Here is the example of yarn global installed package (Parcel JS) not found.

dance2die@CC c:\misc\sources
> yarn global add parcel-bundler
yarn global v1.3.2
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.1.3: The platform "win32" is incompatible with this module.
info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "parcel-bundler@1.3.1" with binaries:
- parcel
Done in 4.84s.
dance2die@CC c:\misc\sources
> parcel
'parcel' is not recognized as an internal or external command,
operable program or batch file.
dance2die@CC c:\misc\sources
>

NOTE: The package name is parcel-bundler but the command is parcel according to the Parcel JS documentation.

After globally installing parcel-bundler, parcel fails with the following error message.

'parcel' is not recognized as an internal or external command, operable program or batch file.

Let's fix this.

Step 1 - Get the yarn global binary path

Let's find out where yarn stores globally installed binary files with yarn global bin command.

dance2die@CC c:\misc\sources
> yarn global bin
C:\Users\dance2die\AppData\Roaming\npm\bin
view raw yarn global bin.cmd hosted with ❤ by GitHub

On my local machine, yarn global add <package> will save files under C:\Users\dance2die\AppData\Roaming\npm\bin.

We need to add that path to Windows Environment Variable Path so that Windows command line interpreter (cmd.exe or powershell.exe) can search the path to find command to run.

Now copy that path to clipboard (e.g. C:\Users\dance2die\AppData\Roaming\npm\bin).

Step 2 - Add the yarn global binary path to PATH environment variable

You can add the path as a system or user variable but I will show you how to add it as a user environment variable (You decide which one to create depending on your situation and permissions).

Click on Windows button then search with "environment" and click on "Edit the system environment variables".

windows environment search

On "System Properties" dialog, click on "Environment Variables..." button.

system properties environment variable button

Select "Path" and click on "Edit..." button.

environment variables edit button

Click on "New" button to add a new path to search.

environment variables new button

Paste the yarn global binary path copied in Step 1 and click "OK"  for all open dialog boxes to save the change.

environment variables new path variable

IMPORTANT NOTE: You need to close all open command line interfaces or start a new instance for the PATH variable to take an effect.

Step 3 - Run the globally installed command

I installed parcel-bundler, which failed to execute previously.

Let's run parcel again on a new command window.

parcel runs

🎉 It works!!! 🎉

Parting Words

I have had so much trouble to get globally added yarn command working on windows since the majority of Google results pointed me to GitHub issues, which dealt with Linux/MacOS only.

I got a hint after seeing this answer on GitHub and failed multiple times to get this working.

I was initially frustrated that create-react-app didn't work with yarn global add so stopped pursuing further but this time (3~4 months later), I decided to do something about it so that I can use yarn all the time.

I hope you can benefit from this post if you are working on front-end projects on Windows as I am.