'yarn global add' command does not work on Windows
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.
Here is the example of yarn global installed package (Parcel JS) not found.
|> yarn global add parcel-bundler|
|yarn global v1.3.2|
|[1/4] Resolving packages...|
|[2/4] Fetching packages...|
|info firstname.lastname@example.org: The platform "win32" is incompatible with this module.|
|info "email@example.com" is an optional dependency and failed compatibility check. Excluding it from installation.[3/4] Linking dependencies...|
|[4/4] Building fresh packages...|
|success Installed "firstname.lastname@example.org" with binaries:|
|Done in 4.84s.|
|'parcel' is not recognized as an internal or external command,|
|operable program or batch file.|
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.
|> yarn global bin|
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 (
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".
On "System Properties" dialog, click on "Environment Variables..." button.
Select "Path" and click on "Edit..." button.
Click on "New" button to add a new path to search.
Paste the yarn global binary path copied in Step 1 and click "OK" for all open dialog boxes to save the change.
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
parcel-bundler, which failed to execute previously.
parcel again on a new command window.
🎉 It works!!! 🎉
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.