Yarn fails with TypeError: Cannot read property 'yarnPath' of null

2.2k Views Asked by At

I am trying to get yarn installed on my mac, yarn installs but running yarn commands hangs with the following error.

>yarn

TypeError: Cannot read property 'yarnPath' of null
    at loadRcFile (/usr/local/lib/node_modules/yarn/lib/cli.js:56945:49)
    at /usr/local/lib/node_modules/yarn/lib/cli.js:56916:14
    at /usr/local/lib/node_modules/yarn/lib/cli.js:101331:14
    at Array.map (<anonymous>)
    at parseRcPaths (/usr/local/lib/node_modules/yarn/lib/cli.js:101329:78)
    at Object.findRc (/usr/local/lib/node_modules/yarn/lib/cli.js:101343:10)
    at getRcConfigForCwd (/usr/local/lib/node_modules/yarn/lib/cli.js:56915:74)
    at /usr/local/lib/node_modules/yarn/lib/cli.js:92694:56
    at Generator.next (<anonymous>)
    at step (/usr/local/lib/node_modules/yarn/lib/cli.js:310:30) 

I have tried uninstalling yarn and reinstalling with

npm uninstall -g yarn && npm install -g yarn 

and that didn't fix this issue. thanks in advance for the help... cheers!

2

There are 2 best solutions below

1
On

I got this error whenever I tried to run the yarn command and solved it by removing a line from a .yarnrc.yml file that was located in the folder in which I was running yarn.

yarnPath: .yarn/releases/yarn-berry.cjs <-- removed this line

Once I did that yarn worked again.

0
On

Ok so from the documentation, its possible you are missing a few things; Below is a step by step process on installing Yarn on Linux (UBUNTU). Try it lets see if you missed anything;

run

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

On Ubuntu 16.04 or below and Debian Stable, you will also need to configure the NodeSource repository to get a new enough version of Node.js.

Then you can simply:

sudo apt update && sudo apt install yarn

Note: Ubuntu 17.04 comes with cmdtest installed by default. If you’re getting errors from installing yarn, you may want to run sudo apt remove cmdtest first.

If using nvm you can avoid the node installation by doing:

sudo apt update && sudo apt install --no-install-recommends yarn

Note: Due to the use of nodejs instead of node name in some distros, yarn might complain about node not being installed. A workaround for this is to add an alias in your .bashrc file, like so: alias node=nodejs. This will point yarn to whatever version of node you decide to use.

If Yarn is not found in your PATH, follow these steps to add it and allow it to be run from anywhere.

Note: your profile may be in your .profile, .bash_profile, .bashrc, .zshrc, etc.

Add this to your profile: export PATH="$PATH:/opt/yarn-[version]/bin" (the path may vary depending on where you extracted Yarn to)

In the terminal, log in and log out for the changes to take effect To have access to Yarn’s executables globally, you will need to set up the PATH environment variable in your terminal. To do this, add export PATH="$PATH:yarn global bin" to your profile, or if you use Fish shell, simply run the command set -U fish_user_paths (yarn global bin) $fish_user_paths

Test that Yarn is installed by running:

yarn --version

This should hopefully do the trick. If not let me know so we see what other solutions there are.