mlb
mlb

Reputation: 59

How to Use Yarn to Install a Local Package Globally?

I have some Node.js CLI code in a folder. To install it globally, I usually cd into its directory and type npm i -g .

What is the equivalent to add a local package taht will work as a global CLI with yarn (yarn global add . returns an error)?

Thanks!

Upvotes: 6

Views: 8779

Answers (2)

user14082
user14082

Reputation: 482

# git-bash for Windows
yarn global add $PWD

# zsh, bash etc. for mac OS
yarn global add file:$PWD 

By the way, I prefer use yarn link and yarn link mySomeCliPackageName

Upvotes: 0

Ryan Rampersad
Ryan Rampersad

Reputation: 331

According to #3256 and #5199 on yarnpkg/yarn, a method that works is:

yarn global add "file:$PWD"

This command assumes the $PWD environment is present, and the command is run from the location the local package is in. You may need to construct an absolute path some other way, if you are not running the command from the same location.

#3256 has some additional notes on how the npm and yarn global installs differ, in terms of the directories used to hold the binaries.

Upvotes: 4

Related Questions