解决 Scoop 的 Yarn 无法使用 global packages 的问题

这个问题出现在 MINGW64 (bash.exe) 环境下,通过 Scoop install 的 Yarn,执行命令 yarn global add eslint,然后执行 eslint 响应 /bin/sh: ...: No such file or directory,目前快速的解决方法如下:

PATH 环境变量添加 %LOCALAPPDATA%\Yarn\config\global\node_modules\.bin
且保证其在最前面

After digging around a bit more I think this is an issue with symlinks from scoop (bin is persisted by scoop and the path depth of the persisted directory scoop/persist/yarn/bin is lower than the depth of the ‘normal’ path scoop/apps/yarn/current/bin) and yarn using relative directories in its shell scripts:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
> $ cat /c/Users/user/scoop/apps/yarn/current/bin/vue
> #!/bin/sh
> basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
>
> case `uname` in
> *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
> esac
>
> if [ -x "$basedir//bin/sh" ]; then
> "$basedir//bin/sh" "$basedir/../../../../../AppData/Local/Yarn/Data/global/node_modules/.bin/vue" "$@"
> ret=$?
> else
> /bin/sh "$basedir/../../../../../AppData/Local/Yarn/Data/global/node_modules/.bin/vue" "$@"
> ret=$?
> fi
> exit $ret
>

$basedir is probably resolved to the persisted bin directory, so $basedir/../../../../.. will resolve to the Windows Users directory (e.g. C:\Users) instead of the user directory of the current user (e.g. C:\Users\user).

This could normally be fixed by setting the global-folder with yarn config set to something like scoop/apps/yarn/current/global but this does not work correctly (see yarnpkg/yarn#5746 and yarnpkg/yarn#5637).

Not sure how to go about this. Editing the .yarnrc file in post_install like in yarnpkg/yarn#5637 doesn’t sound like the best way to do it (it does work though), especially since the file is managed by yarn and the changes might be overridden later on.

I guess the only ‘good’ workaround is to use npm for global installs until the global-folder config does actually work in yarn.

scoop/issues/1641#issuecomment-434775367

本站文章除注明转载外均为原创,未经允许不要转载哇. ヾ(゚ー゚ヾ) http://qwqaq.com/3b2a4407.html
分享到