Do you want to request a _feature_ or report a _bug_?
bug
What is the current behavior?
On Windows when performing a "yarn global install
If the current behavior is a bug, please provide the steps to reproduce.
yarn global install
What is the expected behavior?
On Windows when performing a "yarn global install
Please mention your node.js, yarn and operating system version.
Node: v6.9.1
npm: v3.10.8
yarn: v0.16.1
Windows 7 Enterprise
Good catch... We shouldn't try writing to c:\Program Files\nodejs as the user probably doesn't have permission to write files there (unless running Yarn with admin rights)
Hello !
Is there a reason why yarn isn't using the result of npm config -g get prefix to install global modules ?
On Windows, npm is installing global modules in %APPDATA%\npm by default but the user could have changed the global prefix by running npm config -g set prefix <new/path>
I agree. I am an administrator on my laptop, but my work has my prefix set to %APP_DATA%npm. NPM installs packages global packages to this location. Yarn should read this prefix to know where to install.
Is there a reason why yarn isn't using the result of npm config -g get prefix to install global modules ?
I'm not sure Yarn should care about npm's config. Maybe it's good as a fallback, but Yarn should probably have its own way of configuring this,
On Windows, npm is installing global modules in %APPDATA%npm by default
It should really be using %LocalAppData% :)
Doesn't yarn have to care if it is installing global npm packages? If yarn does not install the npm package where npm is configured to look for global packages them npm won't be able to run the package.
npm won't be able to run the package.
Why would npm be looking for the package? Global packages just need to be on the PATH, and somewhere Yarn knows about them. You don't even need npm to be installed in order to use Yarn (and indeed, on Windows you can just download node.exe without having npm) so Yarn should not be tightly coupled to the npm client.
Maybe I am confused about what yarn is doing. I thought it was giving users a quicker, more streamlined, single way to install packages by searching multiple registries for you such as npm and bower. If the package that you are trying to install is an npm package then yarn would download the package from the npm registry and install that package where npm is configured to install?
Am I correct? If so, doesn't that tie yarn to each registry. If not, the documentation is not clear to me that yarn is installing these packages to a yarn configured location.
While Yarn uses the same registry as npm, it is a separate app from npm, and does not use the npm client at all. This means you can use Yarn on a computer that does not have npm installed, it just requires node.js.
For local packages (ie. packages used by your app), Yarn installs them into node_modules, just like npm does. This is mainly for compatibility reasons - Node.js apps expect their packages to be in node_modules. In this case, we do want to always use the same folder that npm uses.
For global packages (ie. packages that you want to use at the system level, not specific to any particular project), Yarn stores those in its own directory. These do not need to be in any particular location as you should not be require-ing them from your scripts.
In general, any packages or apps used by your project should be installed as local packages, not global. The only global packages that should be installed are those that are not specific to any one project. The main example of this are apps used for scaffolding new projects (for example, Yeoman or create-react-app). Using global packages introduces global state, and like global variables they should be used very sparingly.
If your project uses an npm package with an executable (say something like Webpack, Gulp, etc), you do not need to install it globally. Instead, run the executable from node_modules/.bin/, or use the scripts section in project.json (eg. "build": "gulp build" in project.json's scripts section will actually run ./node_modules/.bin/gulp build when you call npm run build or yarn run build.
Does that help?
This does help. I had encountered my original issue trying to install the angular-cli globally to be able to scaffold new projects.
Is this the reason yarn global add does not work for installing stuff from bin into a place that npm install -g does? I have noticed I have to fall back to npm to do local installations during node package development that contain runnable scripts in the bin directory.
Is there a way I can configure the global prefix for Yarn, to make it install in $(npm config get prefix), on Windows 7? I like my global modules in one place, for which I won't need administrator permissions. I would also prefer npm ls -g --depth=0 and yarn global ls to return the same result.
I am asking, because I just installed gulp-cli and eslint-cli on Windows 7, using Yarn (globally); and when I invoke them; it says command not found.
There is a similar problem on Ubuntu after 'yarn global add gulp'...
Using root, I install gulp globally for all users, but mortals can't access this global copy:
node@44cfab42e83f:~/frontend$ gulp
bash: gulp: command not found
Eventually we discover that yarn put the global gulp in a place that is not accessible to mortals:
root@44cfab42e83f:~/frontend# which gulp
/usr/bin/gulp
root@44cfab42e83f:~/frontend# ls -l /usr/bin/gulp
lrwxrwxrwx 1 root root 53 Dec 23 18:37 /usr/bin/gulp -> ../../root/.config/yarn/global/node_modules/.bin/gulp
Here the problem is that mortals have no permission on the /root directory and so the link is broken.
node@44cfab42e83f:~$ cd /root
bash: cd: /root: Permission denied
node@44cfab42e83f:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="14.04.5 LTS, Trusty Tahr"
node@44cfab42e83f:~$ yarn --version
0.18.1
node@44cfab42e83f:~$ node --version
v6.9.2
node@44cfab42e83f:~$ npm --version
3.10.9
(edited for formatting and to add version info)
Looks like it is still an open issue. Any progress on it?
globals should read in the node path and install to the node_modules at that location.
in windows it currently has Local.APPDATA hard coded in contants.js.
check yarn global bin on CLI, then copy the path to add the global environment path.
Most helpful comment
Hello !
Is there a reason why yarn isn't using the result of
npm config -g get prefixto install global modules ?On Windows, npm is installing global modules in
%APPDATA%\npmby default but the user could have changed the global prefix by runningnpm config -g set prefix <new/path>