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

Can not run globally installed packages which are installed with yarn #2224

Open sharikovvladislav opened 7 years ago

sharikovvladislav commented 7 years ago

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

Bug

What is the current behavior? I can not run globally installed packages (uglifyjs, eslint etc).

Looks like there are problems with path. When I run (you full steps can see below) commands I get errors about path is incorrect. Path is: /d/Dev/nodejs/C:/Users/Vlad/AppData/Local/Yarn/config/global/node_modules/.bin/uglifyjs. It is not problem with uglifyjs. If I will install eslint globally or something like that I am getting same behaviour.

I am trying to do this in Git Bash terminal (MINGW64). If I try to run same command in cmd, cmd window is just disappearing. I also tried to create .cmd file and run commands from this file via: cmdFileName >> xx.txt. I got this in output:

c:\Users\Vlad>eslint --help 
c:\Users\Vlad>"$basedir/C:/Users/Vlad/AppData/Local/Yarn/config/global/node_modules/.bin/eslint.cmd"   "$@" 
c:\Users\Vlad>exit $? 

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

  1. Install yarn with windows installer.
  2. Install uglify-js (or anything else) globally (from npm): Output is:
    Vlad@VladPC MINGW64 /
    $ yarn global add uglify-js
    yarn global v0.17.10
    warning No license field
    [1/4] Resolving packages...
    [2/4] Fetching packages...
    [3/4] Linking dependencies...
    [4/4] Building fresh packages...
    success Installed uglify-js@2.7.5 with binaries:
      - uglifyjs
    warning No license field
    Done in 1.71s.
  3. Use installed package
    Vlad@VladPC MINGW64 /
    $ uglifyjs
    /bin/sh: /d/Dev/nodejs/C:/Users/Vlad/AppData/Local/Yarn/config/global/node_modules/.bin/uglifyjs: No such file or directory

What is the expected behavior?

I expect that I can run uglifyjs (or eslint or any other pacakges) command without errors after it.

Please mention your node.js, yarn and operating system version.

NodeJS v 7.0.0 Yarn v v0.17.10 OS v Windows 7 Ultimate x64

Daniel15 commented 7 years ago

Might be specific to Git Bash or MinGW... Try it in a regular cmd.exe and see if it works there?

sharikovvladislav commented 7 years ago

Nope. cmd.exe is not working too. When I write name of package cmd window just disappears.

12 Дек 2016 г. 3:45 пользователь "Daniel Lo Nigro" notifications@github.com написал:

Might be specific to Git Bash or MinGW... Try it in a regular cmd.exe and see if it works there?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/yarnpkg/yarn/issues/2224#issuecomment-266321221, or mute the thread https://github.com/notifications/unsubscribe-auth/AFXK_jl2aerPmGRLeLRjCA3Mk-6mE8aaks5rHJkdgaJpZM4LKEVk .

builden commented 7 years ago

+1 NodeJS v 7.0.0 Yarn v v0.18.1 Windows 7 Ultimate x64

after yarn global add http-server http-server.cmd create at node.exe root dir

"$basedir/../../Users/{username}/AppData/Local/Yarn/config/global/node_modules/.bin/http-server.cmd"   "$@"
exit $?

console can't known the $bashdir path

sharikovvladislav commented 7 years ago

Hm. I am trying to get what is /d/Dev/nodejs/ prefix ($basedir). I don't even have this directory at the disk. I don't have any NODE_PATH env variable (or smth like that) with /d/Dev/nodejs/

modulexcite commented 7 years ago

I have the same exact problem when installing global packages using yarn and I have the same environment as @sharikovvladislav. I tried installing different packages globally with similar results and none of the packages installed globally are available from cmd. Any help would be greatly appreciated.

polizz commented 7 years ago

Was able to repro. I tracked the issue down to the cmd-shim library. There is an open PR that solves this. When I updated my shim to the new code below, it executes as expected.

.....global\node_modules.bin\uglifyjs.cmd

@ECHO.%0 | FINDSTR /C:\ /C:/ >NUL && (
    SET dir=%~dp0
) || (
    FOR /F %%i IN ('where %0') DO @SET dir=%%~dpi
)
@IF EXIST "%dir%\node.exe" (
  "%dir%\node.exe" "%dir%\..\uglify-js\bin\uglifyjs %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node "%dir%\..\uglify-js\bin\uglifyjs" %*
)

I did run into a separate issue where my Yarn bin path wasn't set correctly. I use the nodist node version manager on this machine. The choco Yarn install set C:\Users\andre\AppData\Local\Yarn\.bin, however the global installs were actually going to: C:\Users\andre\AppData\Local\Yarn\config\global\node_modules\.bin.

After manually setting that path, the above workaround script functioned as expected.

markheron91 commented 7 years ago

I ran into this error as well, but before checking online I decided to try upgrading yarn to see if that fixed my problem - only problem is now the yarn package itself is showing this error. I've tried removing the files manually from the appData\local\yarn folder but it is still showing me the error.

Any idea how I can remove the packages from yarn and use npm instead for now as all of my work code written with angular-cli is now unusable until either this is fixed or I can get my "ng" command to point back to an npm version.

modulexcite commented 7 years ago

You should check the global folder %LocalAppData%\Yarn\config\global\node_modules% for any remnants of the globally installed packages using yarn and delete them manually if they are not removed after using yarn remove <package> --global. Also check the path of your node installation using where node from command line and delete any script files in the root directory named as your package that were installed globally using yarn. For example, I have node installed under %ProgramFiles(x86)\ndoejs% on a 64-bit machine and had to delete both ng and ng.cmd files when I installed angular-cli globally using yarn.

markheron91 commented 7 years ago

@modulexcite ah, I had deleted all the files from the global/node_modules folder but I hadn't deleted the ones from inside the nodejs installation - thanks 😄

modulexcite commented 7 years ago

@markheron91 Glad to help, hopefully this will get fixed in the next release.

iwsfg commented 7 years ago

Nope. cmd.exe is not working too. When I write name of package cmd window just disappears.

Now that #1043 landed behaviour described in the quote is gone, but global packages still wont run from MINGW64. (At least it works from cmd). Here's what I'm seeing:

Iwasawafag@home:/c/dev/whatever (master)
$ where rimraf
C:\Program Files\nodejs\rimraf
C:\Program Files\nodejs\rimraf.cmd

Iwasawafag@home:/c/dev/whatever (master)
$ rimraf
/bin/sh: /c/Program Files/nodejs/../../Users/Iwasawafag/AppData/Local/Yarn/config/global/node_modules/.bin/rimraf: No such file or directory

Contents of both /c/Program Files/nodejs/rimraf and ~/AppData/Local/Yarn/config/global/node_modules/.bin/rimraf could be found in this gist

I guess for now I still have to use npm for installation of global packages if I want those to work in Git Bash

enterit commented 7 years ago

+1 In my case yarn install browserify creates a file D:\DevTools\nodejs\browserify.cmd:

@"%~dp0\C:\Users\myuser\AppData\Local\Yarn\config\global\node_modules\.bin\browserify.cmd"   %*

In this case executable path gets resolved to D:\DevTools\nodejs\\C:\Users\myuser\AppData\Local\Yarn\config\global\node_modules\.bin\browserify.cmd

This is obviously wrong.

To clarify, this only happens when I have Yarn installed via Chocolatey, and then Yarn is installed to C:\Program Files (x86)\Yarn\bin\yarn.cmd

If Yarn is installed using npm install -g yarn, then it gets installed to D:\DevTools\nodejs\yarn.cmd. In this case yarn install -g browserify generates

@"C:\Users\myuser\AppData\Local\Yarn\config\global\node_modules\.bin\browserify.cmd"   %*

My Yarn version is 0.19.1.

modulexcite commented 7 years ago

This issue was resolved in v0.19.1. I'm now able to install packages globally using yarn.

iwsfg commented 7 years ago

But can you use them from MINGW64?

modulexcite commented 7 years ago

@Iwasawafag I can run globally installed packages using yarn (v0.19.1) from MINGW64. FYI, I'm on Windows 7 64-bit with git 2.10.2

sharikovvladislav commented 7 years ago

I tried to install packages globally with yarn. Everything worked fine. I also tried it from MINGW64.

I think this can be closed as resolved.

iwsfg commented 7 years ago

@Iwasawafag I can run globally installed packages using yarn (v0.19.1) from MINGW64. FYI, I'm on Windows 7 64-bit with git 2.10.2

Hm... I'm also on Win 7 x64 with git 2.10.0.windows.1. This got me to try and change few things and I noticed different behavior:

When %programfiles%/nodejs is a symlink (in my case managed by nvm-windows (and well, not a symlink, but NTFS junction)) yarn global add <package-name> creates two scripts in that folder for every globally installed package. For instance, "rimraf" and "rimraf.cmd" both of which just trying to call appropriate script from global-folder. But whenever it's an actual folder created by Node's installer – no files are being created inside of it.

I don't know in which case it works incorrectly. Considering that Yarn's installer does not add anything else to PATH to make global packages available it looks like it's supposed to create those scripts in node's dir. I fixed it for myself by prepending %localappdata%\Yarn\config\global\node_modules\.bin to PATH (with %localappdata% resolved).

Perhaps, I should open another issue about this behavior.

mrkishi commented 7 years ago

@Iwasawafag Your problem is probably related to prefix. What does your yarn global bin return?

It seems in the absence of a prefix being provided either through yarn config or flags, yarn tries to use the process path as a prefix. That's probably not working in your setup.

iwsfg commented 7 years ago

yarn global bin says C:\Program Files\nodejs regardless of whether it's junction point or a directory...... Rrright, it didn't have write access when it was a directory, didn't think of that. Changed permissions, scripts are being generated again.

Now I see what's going on. It has something to do with C:\Program Files\nodejs being a junction point. When it's a directory - it works fine and when it's not I get same error as I posted above (/bin/sh: /c/-snip-/.bin/rimraf: No such file or directory). So it's a problem with MinGW64.

Thanks for helping me figure this out

Crecket commented 7 years ago

I was using Git along with Cmder which was still using 2.6.3.windows.1. After updating Git to 2.11.0.windows.3 yarn is giving me output again.

phxism commented 7 years ago

This problem occurs again. Node v6.10.0, Yarn 0.20.3, npm v3.10.9, Git 2.10.2, OS Win7x64SP1 Node Path:E:\Dev\nodejs\ I install yarn with msi installer,when i run"yarn global add vue-cli", the text of"E:\Dev\nodejs\vue.cmd" is @"%~dp0\C:\Users\HAP\AppData\Local\Yarn\config\global\node_modules\.bin\vue.cmd" %* It is wrong.

carlosvigil commented 7 years ago

Same issue on Mac, happens every time I run an update alias including yarn global upgrade. Just gonna use npm now...

delebash commented 7 years ago

yarn 0.21.3 node 7.8.0 windows 7x64 Same problem as @enterit

Example:

Installed gulp as global

Resulting gulp.bat in F:\Program Files\nodejs

@"%~dp0\C:\Users\user.name\AppData\Local\Yarn\config\global\node_modules.bin\gulp.cmd" %*

expands to

@"F:\Program Files\nodejs\C:\Usersuser.namel\AppData\Local\Yarn\config\global\node_modules.bin\gulp.cmd"

The batch file does not like %~dp0 (expands to F:\Program Files\nodejs\) if you remove %~dp0\ and just use @"C:\Users\user.name\AppData\Local\Yarn\config\global\node_modules.bin\gulp.cmd" %* it works, this is assuming that you have F:\Program Files\nodejs in your path variable which should get added automatically when you install nodejs.

olivierlacan commented 7 years ago

FYI I once installed yarn via npm (I know, bad idea) and yarn global bin became set to ~/.nvm/versions/node/v5.5.0/bin (macOS).

I had to use yarn config set prefix /usr/local/ (since /usr/local/bin is on my $PATH and therefore will load binaries installed within in) based on the advice suggested here: https://github.com/yarnpkg/yarn/issues/630#issuecomment-277837483

Of course I had to reinstall the package with the binary (in my case gulp) after setting the global binary installation directory.

But of course the binary I had installed via npm was still being loaded via the nvm binary directory (which I added to my $PATH as well), as I noticed by doing:

$ which -a gulp
/Users/olivierlacan/.nvm/versions/node/v5.5.0/bin/gulp
/usr/local/bin/gulp

This meant I had to remove that file (rm /Users/olivierlacan/.nvm/versions/node/v5.5.0/bin/gulp) to prevent it from taking precedence on the yarn-installed gulp binary since /usr/local/bin appears later in my $PATH than /Users/olivierlacan/.nvm/versions/node/v5.5.0/bin.

Hope that helps others in a similar situation.

tdmalone commented 7 years ago

Same issue here, but thanks to the above comments I noticed that my bin dir (C:\Users\Tim\appdata\local\yarn\bin) was not in PATH. I'm not sure why... but at least adding it to PATH was a quick fix.

Daniel15 commented 7 years ago

That's interesting... The installer should have added it to the path. So far I haven't been able to replicate any issues with the path missing after installing Yarn.

Sent from my phone.

On Oct 11, 2017 12:57 PM, "Tim Malone" notifications@github.com wrote:

Same issue here, but thanks to the above comments I noticed that my bin dir (C:\Users\Tim\appdata\local\yarn\bin) was not in PATH. I'm not sure why... but at least adding it to PATH was a quick fix.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/yarnpkg/yarn/issues/2224#issuecomment-335658676, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFnHRUaGPSy5L_eS9SZdE_vNa6vB9t5ks5srCCjgaJpZM4LKEVk .

iki commented 6 years ago

Interesting, installed latest Yarn 1.2.1 with npm i -g yarn, and there's no %LocalAppData%\Yarn\bin directory at all.

Actually, there're only cache and config directories in %LocalAppData%\Yarn.

I found all the shell scripts and .cmd scripts in %LocalAppData%\Yarn\config\global\node_modules\.bin.

Also, there was no yarn path added to the system path.

I added the .bin path to the system path manually, and everything works fine.

Questions:

  1. Is %LocalAppData%\Yarn\bin deprecated, and yarn will use %LocalAppData%\Yarn\config\global\node_modules\.bin, or is the missing Yarn/bin path error of installing via npm and should be reported?
  2. Is the missing path in system path error of installing via npm and should be reported?
barbalex commented 6 years ago

I do not remember how I originally installed yarn.

To be sure I removed it using npm remove -g yarn. Then used the windows installer to reinstall it.

Now there is still no bin folder in C:\Users\alex\AppData\Local\Yarn. It's path does exist in path: C:\Users\alex\AppData\Local\Yarn\bin.

And global installs are not found when typed in the console.

dandv commented 6 years ago

I've installed polymer-cli globally on a Linux box, but polymer isn't in the path.

~ yarn global add polymer-cli
yarn global v1.3.2
[1/4] Resolving packages...
warning polymer-cli > bower@1.8.2: ...psst! Your project can stop working at any moment because its dependencies can change. Prevent this by migrating to Yarn: https://bower.io/blog/2017/how-to-migrate-away-from-bower/
warning polymer-cli > babel-preset-es2015@6.24.1: 🙌  Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update! 
warning polymer-cli > polyserve > @types/assert@0.0.29: See https://github.com/DefinitelyTyped/DefinitelyTyped/issues/12826
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "polymer-cli@1.5.7" with binaries:
      - polymer
Done in 25.08s.
➜  19:17 polymer
zsh: command not found: polymer
➜  19:17 polymer-cli init
zsh: command not found: polymer-cli
➜  19:17 yarn --version
1.3.2
Daniel15 commented 6 years ago

@dandv - Are you sure the Yarn directory is in your path? Try echo $PATH.

sharikovvladislav commented 6 years ago

hm.

Is this problem still exists?

I don't have this even on yarn v 1.0.2. I am not able to reproduce this.

dandv commented 6 years ago

@Daniel15 - I have the path problem using zsh. echo $PATH doesn't show it including ~/.yarn/bin.

Daniel15 commented 6 years ago

echo $PATH doesn't show it including ~/.yarn/bin.

This means you haven't added it to your $PATH. You'll need to edit your ~/.zshrc file :)

maximelebreton commented 6 years ago

thanks @modulexcite, your https://github.com/yarnpkg/yarn/issues/2224#issuecomment-269771825 solve my problem.

in my case, i tried to install globally parcel-bundler with yarn, and get this message when I tried to launch parcel:

"$basedir/../../Users/{username}/AppData/Local/Yarn/config/global/node_modules/.bin/parcel.cmd"   "$@"
exit $?

After several failed attempts, I finally came across your comment, found parcel, parcel.cmd & parcel.cmd.cmd files in my node folder (C:\Program Files\nodejs), deleted them, and now it works.

moracabanas commented 6 years ago

I am still experiencing this error on windows while I install any package like @vue/cli globally with yarn global add @vue/cli it installs correctly but the vue-cli binaries are located at C:\Users\**youruser**\AppData\Local\Yarn\bin. You have to add this path to the Environment Variables Path to make any package installed globally from yarn to be available on Powershell or CMD.

xianghongai commented 6 years ago

windows 10 : $ sysdm.cplAdvancedEnvironment VariablesSystem variablesPATHNew%LocalAppData%\Yarn\Data\global\node_modules\.bin\ → restart Command Prompt

moracabanas commented 6 years ago

Thanks for spot that. But I still miss why that path should have been manually added

nerdoc commented 5 years ago

This is still correct. I just tested with npm install -g @vue/cli - works great. Same with yarn: yarn global add @vue/cli - everything is installed, but vuecan't be called, because it's not in the path. Ubuntu 18.04, nvm-> node 12.5.0.