20

Mac OS 10.13.6

How did I install yarn

npm install --global yarn

yarn installation path is /Users/useName/.config/yarn

Then ran below command

yarn create react-app app-name

This worked well, but when I'm trying to run yarn add package_name, it's throwing error

bash: yarn: command not found

The weird thing, after closing and opening terminal again under which I had globally ( ? ) installed yarn, the yarn command is not found.

1
  • Srrange. Could you please post the contents of your bashrc file. Commented Mar 17, 2021 at 8:17

8 Answers 8

14

Just re- install using "brew install yarn" and that should solve it.

1
  • this simple solution worked for me
    – utkarsh
    Commented Nov 7, 2023 at 12:25
10

Execute this on your Mac command line:

export PATH=~/.npm-global/bin:$PATH.

This will set the NPM PATH DIRECTORY

0
5

try export PATH=~/.yarn/bin:$PATH into .profile !**

or

try: If you are on the bash try adding alias yarn=~/.yarn/bin/yarn.js

We no longer support global installation of Create React App.

Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app

The latest instructions for creating a new app can be found here:

create-react-app.dev/docs/getting-started

@github ;)

Try this Stackoverflow :)

8
  • This solution didn't work for me, I've edited question and added yarn directory on Mac
    – vikramvi
    Commented Mar 16, 2021 at 6:16
  • 1
    Did you tried installing yarn through homebrew package manager brew install yarn Commented Mar 16, 2021 at 7:17
  • what does yarn --version says Commented Mar 16, 2021 at 7:18
  • did you do yarn init Commented Mar 16, 2021 at 7:23
  • I don't want to install using brew but with npm way. yarn --version just gives error message "command not found"
    – vikramvi
    Commented Mar 16, 2021 at 9:48
5

Per this Yarn Installation guide "The preferred way to manage Yarn is through Corepack, a new binary shipped with all Node.js releases starting from 16.10."

As of 2023 - on a Mac - for Node.js >=16.10 - this worked for me after updating node to 16.17:

corepack enable
2
  • 2 days troubleshooting this on Mac M1. Yarn "segmentation fault" in VSCode terminal, but regular Mac terminal was fine. Followed this suggestion (use the link above for details) and finally fixed!
    – Oprimus
    Commented Aug 10, 2023 at 20:21
  • I could kiss you right now, such an amazing fix
    – Foxhoundn
    Commented Jan 30 at 16:06
3

If you are using nodenv and yarn is not working try a simple

$nodenv rehash

after that yarn should work

1

Global packages won't be installed in a user account. The path you mention is for configuration. Try to find where Yarn was really installed or just try export PATH=/usr/local/bin:$PATH (that's where Yarn is on my machine).

2
  • can you clarify how did you install yarn & which OS you've ?
    – vikramvi
    Commented Mar 18, 2021 at 4:53
  • Sorry, I should have mentioned that I'm using MacOS 10.15.7. I installed yarn with Homebrew.
    – nydame
    Commented Mar 22, 2021 at 0:54
1

You may try:

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc

if you have installed yarn via homebrew.

0

After npm i -g yarn I had to manually add npm packages to my $PATH. Adding these two lines to my ~/.profile fixed it, after restarting the Terminal the yarn command became available:

NPM_PACKAGES="${HOME}/.npm-packages"
export PATH="$NPM_PACKAGES/bin:$PATH"

I found them in my ~/.bashrc but somehow it was not executed.

2
  • Which OS are you using ? I'm on Mac and I don't see ~/.profile there.
    – vikramvi
    Commented Apr 12, 2021 at 11:38
  • 1
    I'm on macOS 11.2.3, I had to create ~/.profile too Commented Apr 12, 2021 at 12:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.