yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.43k stars 2.72k forks source link

"yarn global add" / "yarn global bin" do not work correctly in MinGW (ie, Git Bash on Windows). "npm install -g" works correctly. #2993

Closed gkovacs closed 6 years ago

gkovacs commented 7 years ago

yarn 0.21.3

Do you want to request a feature or report a bug? Bug

What is the current behavior? When I run yarn global add gulp-cli on Windows within the Git Bash shell (MinGW), it doesn't install the command. I looked into the reason and it seems it isn't detecting that it's running within MinGW. So the path it should be installing to is /c/Users/geza/AppData/Roaming/npm but the output of yarn global bin is C:\Program Files\nodejs

If the current behavior is a bug, please provide the steps to reproduce.

This is on a fresh install of Windows 10 Enterprise, 64-bit

1) install nodejs (I installed the latest version, 7.7.4). go with the default options (ie, let it install nodejs to the windows PATH) 2) install git for for windows from https://git-for-windows.github.io/ (I installed the latest version, 2.12.1). again, go with the default options (ie, let it install git to the windows PATH). 3) reboot windows so we have git and node in our PATH 4) open the Git Bash shell 5) run npm install -g yarn to install yarn 6) run yarn global add gulp-cli 7) run gulp

The gulp command is not found. if we check /c/Users/geza/AppData/Roaming/npm then there is no file named gulp there

if we instead run npm install -g gulp-cli then the gulp binary shows up at /c/Users/geza/AppData/Roaming/npm and gulp works.

What is the expected behavior? I expect yarn global add gulp-cli to have the same behavior within MinGW as npm install -g gulp-cli - ie, after running then the gulp binary is added to /c/Users/geza/AppData/Roaming/npm

Please mention your node.js, yarn and operating system version. node 7.7.4 yarn 0.21.3 windows 10 education, 64-bit, version 1607, OS build 14393.953 git for windows 2.12.1

Here's my PATH within Git Bash:

echo $PATH
/c/Users/geza/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/geza/bin:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Program Files/nodejs:/cmd:/c/Users/geza/AppData/Local/Microsoft/WindowsApps:/c/Users/geza/AppData/Roaming/npm
gkovacs commented 7 years ago

Actually it seems I can reproduce this issue on Ubuntu 16.04 as well:

sudo npm install -g yarn
sudo yarn global add gulp-cli

And yet gulp is not showing in /usr/bin/ or anywhere on the PATH (whereas running sudo npm install -g gulp-cli does work as expected, installing the gulp command at /usr/bin/gulp).

Unlike in the case of MinGW on Windows, the output of yarn global bin is correct on Ubuntu /usr/bin

node 7.7.4 yarn 0.21.3 Ubuntu 16.04 LTS (xenial)

balupton commented 7 years ago

I'm getting this on MacOS 10.12.4 (16E195)

$ yarn global bin
/Users/balupton/.nvm/versions/node/v7.7.4/bin

$ ls /Users/balupton/.nvm/versions/node/v7.7.4/bin
node    npm yarn    yarnpkg

$ echo $PATH
/Users/balupton/Applications/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin:/Users/balupton/.nvm/versions/node/v7.7.4/bin:/Users/balupton/.gems/bin:/usr/local/opt/ruby/bin:/Users/balupton/.go/bin:/Users/balupton/bin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/Users/balupton/.scripts/commands:./node_modules/.bin:

$ yarn global add npm-check-updates
yarn global v0.21.3
warning No license field
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
[4/4] πŸ“ƒ  Building fresh packages...
success Installed "npm-check-updates@2.10.4" with binaries:
      - npm-check-updates
      - ncu
warning No license field
✨  Done in 14.81s.

$ ncu -a
-bash: ncu: command not found

$ ls /Users/balupton/.nvm/versions/node/v7.7.4/bin
node    npm yarn    yarnpkg

$ yarn global ls
yarn global v0.21.3
warning No license field
info "aurelia-cli@0.26.1" has binaries:
   - aurelia
   - au
info "now@4.5.3" has binaries:
   - now
info "npm-check-updates@2.10.4" has binaries:
   - npm-check-updates
   - ncu
info "slap@0.1.61" has binaries:
   - slap
info "surge@0.18.0" has binaries:
   - surge
✨  Done in 10.69s.

Strangely, the yarn global ls detects the installed packages, so it seems they are being installed somewhere else, that yarn global bin is lying about.

balupton commented 7 years ago

Okay removing it and adding it again makes it work:

$ yarn global remove npm-check-updates
yarn global v0.21.3
[1/2] Removing module npm-check-updates...
[2/2] Regenerating lockfile and installing missing dependencies...
warning No license field
success Uninstalled packages.
✨  Done in 31.82s.

$ ls "$(yarn global bin)"
node    npm yarn    yarnpkg

$ yarn global ls
yarn global v0.21.3
warning No license field
info "aurelia-cli@0.26.1" has binaries:
   - aurelia
   - au
info "now@4.5.3" has binaries:
   - now
info "slap@0.1.61" has binaries:
   - slap
info "surge@0.18.0" has binaries:
   - surge
✨  Done in 9.47s.

$ yarn global add npm-check-updates
yarn global v0.21.3
warning No license field
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
[4/4] πŸ“ƒ  Building fresh packages...
success Installed "npm-check-updates@2.10.4" with binaries:
      - npm-check-updates
      - ncu
warning No license field
✨  Done in 14.34s.

$ ls "$(yarn global bin)"
ncu         node            npm         npm-check-updates   yarn            yarnpkg

$ ncu -a
Using /Users/balupton/Projects/active/taskgroup/package.json
βΈ¨β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘βΈ© β ‹ :
All dependencies match the latest package versions :)

Here's what I'm guessing is the problem.

You install node with nvm like so:

nvm install v7.5.0
npm install -g yarn
yarn global add npm-check-updates
ls "$(yarn global bin)"

Which is fine and dandy, yarn installs npm-check-updates to the /Users/balupton/.config/yarn/global folder, and puts the bin inside /Users/balupton/.nvm/versions/node/v7.7.4/bin

However, if you install a new version of node:

nvm install v7.7.4
ls "$(yarn global bin)"

Then /Users/balupton/.nvm/versions/node/v7.7.4/bin is empty. However /Users/balupton/.config/yarn/global remains the same.

So when you do a yarn global add ... it just checks that /Users/balupton/.config/yarn/global is the same, and never checks /Users/balupton/.nvm/versions/node/v7.7.4/bin which the files are missing.

Doing a yarn global remove npm-check-updates removes it from /Users/balupton/.config/yarn/global such that a yarn global add npm-check-updates does the /Users/balupton/.config/yarn/global check, which determines it needs to be properly installed, and adds the /Users/balupton/.nvm/versions/node/v7.7.4/bin correctly.

balupton commented 7 years ago

It would be nice if yarn global bin returned /Users/balupton/.config/yarn/bin or /Users/balupton/.config/yarn/global/.bin instead

BYK commented 6 years ago

This shouldn't be an issue anymore so closing. Reopen please if you think it is still a problem.