Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn global packages are installed unproperly #1641

Closed
exarus opened this issue Aug 7, 2017 · 21 comments
Closed

Yarn global packages are installed unproperly #1641

exarus opened this issue Aug 7, 2017 · 21 comments

Comments

@exarus
Copy link

exarus commented Aug 7, 2017

Yarn that was installed via Scoop doesn't install global packages properly.

TL;DR: Suggested hot fix workaround

If you are a Scoop user and want to fix the bug ASAP than you may add %LOCALAPPDATA%\Yarn\config\global\node_modules\.bin to your PATH environment variable.

Test scenario:

I have Windows 10 desktop with fresh Scoop installed. After that:

scoop install nodejs yarn
yarn global add http-server

The last command generated file $env:HOMEPATH\scoop\apps\yarn\current\bin\http-server.cmd.
Scoop previously added this file's folder to $env:PATH.
This file contains only 1 non-empty line:

@"%~dp0\..\..\..\..\AppData\Local\Yarn\config\global\node_modules\.bin\http-server.cmd"   %*

The command http-server returns following output:

The system cannot find the path specified.

Bug source

I've tried to find the bug reason. So I've edited the file and added 1 more ..\ right before AppData:

@"%~dp0\..\..\..\..\..\AppData\Local\Yarn\config\global\node_modules\.bin\http-server.cmd"   %*

The resulting file works.

The same issue is reproduced with any global Yarn package. We have to figure out if this a Scoop or Yarn issue.

@deevus
Copy link
Member

deevus commented Aug 7, 2017

@Daniel15 are there any known issues with yarn global on Windows?

@r15ch13
Copy link
Member

r15ch13 commented Aug 7, 2017

I have installed scoop to D:\scoop which results in:

@"%~dp0\C:\Users\r15ch\AppData\Local\Yarn\config\global\node_modules\.bin\http-server.cmd"   %*

@r15ch13
Copy link
Member

r15ch13 commented Aug 7, 2017

It has something to do with prefix in the %userprofile%\.yarnrc.
Can also be reproduced by
yarn global add http-server --prefix "C:\\Users\\exarus\\scoop\\persist\\yarn\\bin"
yarn global add http-server --prefix "D:\\scoop\\persist\\yarn\\bin"

I stumbled over this issue at the time I added the prefix to .yarnrc. See comments on e4cc2c3

@Daniel15
Copy link
Contributor

I have installed scoop to D:\scoop which results in:

@r15ch13 - This is a known bug with cmd-shim: npm/cmd-shim#21

@exarus
Copy link
Author

exarus commented Aug 13, 2017

@r15ch13, @Daniel15 The bug with different drives might be related to cmd-shim. But the bug with the invalid resolved path on the same drive is not a cmd-shim issue.

@Daniel15
Copy link
Contributor

It might be due to how cmd-shim is being invoked by Yarn. Does Scoop use symlinks? Perhaps Yarn is doing strange things with symlinks on Windows.

@deevus
Copy link
Member

deevus commented Sep 14, 2017

@Daniel15 Yes the currently installed version is symlinked to ~/scoop/apps/yarn/current

@dsbert
Copy link
Contributor

dsbert commented Nov 3, 2017

I'm running into this issue as well. Typing yarn global bin outputs C:\Users\usr\scoop\persist\yarn\bin\bin for me. I do see the globally installed modules in that folder.

Checking my path variable, the following are both present.

C:\Users\usr\scoop\apps\yarn\current\Yarn\bin
C:\Users\usr\scoop\apps\yarn\current\bin

@bogdan-d
Copy link

I have a similar issue but only while using git bash, in the cmd shell it seems to work. (Windows 10)
I installed yarn 1.5.1 using scoop, then I installed eslint globally using yarn:

MINGW64:

$ eslint
/bin/sh: /c/Users/mrglass/scoop/apps/yarn/current/bin/../../../../../AppData/Local/Yarn/Data/global/node_modules/.bin/eslint: No such file or directory

CMD:

C:\Users\mrglass\Desktop>eslint
eslint [options] file.js [file.js] [dir]
...

@akuntsch
Copy link

Same issue here with Git Bash. Works fine in cmd and PowerShell.

$ vue
/bin/sh: /c/Users/user/scoop/apps/yarn/current/bin/../../../../../AppData/Local/Yarn/Data/global/node_modules/.bin/vue: No such file or directory

I think this might be an issue with Git Bash rather than scoop though, since ls also fails (on the file and the .bin directory):

$ ls /c/Users/user/scoop/apps/yarn/current/bin/../../../../../AppData/Local/Yarn/Data/global/node_modules/.bin/vue
ls: cannot access '/c/Users/user/scoop/apps/yarn/current/bin/../../../../../AppData/Local/Yarn/Data/global/node_modules/.bin/vue': No such file or directory
$ ls /c/Users/user/scoop/apps/yarn/current/bin/../../../../../AppData/Local/Yarn/Data/global/node_modules/.bin/
ls: cannot access '/c/Users/user/scoop/apps/yarn/current/bin/../../../../../AppData/Local/Yarn/Data/global/node_modules/.bin/': No such file or directory

However, cd does work on the .bin directory and the file obviously exists:

$ cd /c/Users/user/scoop/apps/yarn/current/bin/../../../../../AppData/Local/Yarn/Data/global/node_modules/.bin/
$ ls
vue*  vue.cmd

@akuntsch
Copy link

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:

$ 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.

@chawyehsu
Copy link
Member

chawyehsu commented Oct 31, 2018

I have a variant manifest of yarn: dorado/yarn.json, which doesn't change the location of (or persist) yarn's global bin, I think you should try it. Previously I suggested to keep yarn's original location of global bin in #1862, but it didn't accepted, so I create the variant one.

@DanielRuf
Copy link

@r15ch13 - This is a known bug with cmd-shim: npm/cmd-shim#21

Well, the last commit was 3 years ago. Do we still use this outdated package for Yarn?

@DanielRuf
Copy link

If you are a Scoop user and want to fix the bug ASAP than you may add %LOCALAPPDATA%\Yarn\config\global\node_modules\.bin to your PATH environment variable.

The correct path is now %LOCALAPPDATA%\Yarn\Data\global\node_modules\.bin.
config => Data

@masaeedu
Copy link
Contributor

@DanielRuf Is this the same path that would be returned by yarn global bin? On the system I'm testing with (Win 10, yarn 1.12.3) I get ~\AppData\Local\Yarn\bin instead.

@DanielRuf
Copy link

~\AppData\Local

This is the same, %LOCALAPPDATA% is an alias.

@masaeedu
Copy link
Contributor

masaeedu commented Mar 25, 2019

@DanielRuf Yes, I'm aware of that, but the last part of the path differs. The suffix I'm seeing to %LOCALAPPDATA%\Local\Yarn is bin, whereas in the path you provided it's Data\global\node_modules\.bin. I'm not sure which one is correct.

@DanielRuf
Copy link

Should be the same.

@niheaven
Copy link
Member

It's fixed in #3206 (Yarn 1.15.2), please update and try again.

PS. the yarn global bin is left alone, that dir is not add to $env:PATH and is needless for scoop installed yarn.

@JustinGrote
Copy link

JustinGrote commented Jul 10, 2019

@niheaven this is still not fixed for me, it appears prefix still needs to be added or some yarn installs like azure-functions-core-tools still end up in %localappdata%.

As the bucket has moved to its own repository I willl reopen the issue there.

EDIT: PR Here: ScoopInstaller/Main#232

@I-Want-ToBelieve
Copy link

Executing a command in PowerShell can quickly set environment variables to alleviate this problem

$env:PATH="$env:PATH;$env:LOCALAPPDATA\Yarn\bin"
[Environment]::SetEnvironmentVariable("PATH", "$env:PATH", "User")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests