35

I'd like to see a list of all yarn linked packages everywhere on my computer and then run a command to unlink all of them. Can anyone help me out here?

Thanks!

tnrich
  • 8,006
  • 8
  • 38
  • 59

5 Answers5

42

Don't know if this is the yarn way to do things, but I just :

rm -rf ~/.config/yarn/link/*

Loheek
  • 1,865
  • 17
  • 28
8

You can create aliases

alias yarn-linked="find . -type l | grep -v .bin | sed 's/^\.\/node_modules\///'"
alias yarn-unlink-all="yarn-linked | xargs yarn unlink && yarn install --check-files"

Credit hubgit

zavr
  • 2,049
  • 2
  • 18
  • 28
  • This is closer to what I want but when I try running yarn-unlink-all I get a bunch of warnings: find: ./Library/Containers/com.apple.VoiceMemos: Operation not permitted .. etc ... find: ./Library/Containers/com.apple.archiveutility: Operation not permitted xargs: yarn: Argument list too long – tnrich Mar 03 '20 at 18:03
  • i don't have this problem... hm did you update ` ~/.bash_profile` exactly with the code? if you just copy and paste these 2 lines into terminal, and run yarn-unlink-all, you get the errors? – zavr Mar 03 '20 at 19:12
  • actually this is not to unlink from your whole computer, just local CWD packages – zavr Mar 03 '20 at 19:13
  • Added yarn-linked to package.json and got `error An unexpected error occurred: "/home/vitaly/myproject/package.json: Unexpected token . in JSON at position 833".` – Vitaly Zdanevich Jul 27 '22 at 16:39
4

There is an Issue for this feature.

The only surefire way I know of is to nuke node_modules:

rm -rf node_modules && yarn

I know, I know, horrible solution. If someone knows a better way, please inform.

Matthias
  • 13,607
  • 9
  • 44
  • 60
2

Links are registered in ~/.config/yarn/link. To reverse this process or unlink, simply use:

yarn unlink

or

yarn unlink [package]

EDIT:

You can try by add following in bash.rc:

alias yarn-linked="find . -type l | grep -v .bin | sed 's/^\.\/node_modules\///'" 
alias yarn-unlink-all="yarn-linked | xargs yarn unlink && yarn install --check-files" 
Muhammad Zeeshan
  • 4,608
  • 4
  • 15
  • 41
  • Is there a way to unlink all of them at the same time through a single command? – tnrich Mar 02 '20 at 04:57
  • 1
    This i found online check my answer for credit you need 2 lines in bash.rc `alias yarn-linked="find . -type l | grep -v .bin | sed 's/^\.\/node_modules\///'"` `alias yarn-unlink-all="yarn-linked | xargs yarn unlink && yarn install --check-files"` – zavr Mar 02 '20 at 12:39
  • `yarn unlink` is not an "unlink all" command. It only works in each individual package directory from which you ran `yarn link` – Matthias Nov 21 '20 at 16:24
  • Thanks @zavr Running the command `yarn install --check-files` show the message : warning The target of linked package "my-package" is missing. Removing link. – Alex83690 Feb 12 '21 at 09:19
2

On Linux, they are stored in ~/.config/yarn/global

and you can remove with command yarn unlink [package]

Hope this will Help

https://stackoverflow.com/a/43747805/12318562

Arpit Vyas
  • 2,118
  • 1
  • 7
  • 18
  • Is there a way to unlink all of them at the same time through a single command? – tnrich Mar 02 '20 at 04:57
  • npm uninstall `ls -1 node_modules | tr '/\n' ' '` this will remove all packges with npm but yarn doesn't provider command to remove all packges with single command. – Arpit Vyas Mar 02 '20 at 11:18