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 install installs package under nodejs node_modules instead of appdata node_modules #1491

Open
joswalt opened this issue Oct 26, 2016 · 15 comments
Labels

Comments

@joswalt
Copy link

joswalt commented Oct 26, 2016

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 " the install is downloaded to the "C:\Program Files\nodejs" node_modules folder instead of the "C:\Users[Username]\AppData\Roaming\npm" node_modules folder.

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 " the install is downloaded to the "C:\Program Files\nodejs" node_modules folder instead of the "C:\Users[Username]\AppData\Roaming\npm" node_modules folder.

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

@Daniel15
Copy link
Member

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)

@maxence-lefebvre
Copy link

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>

@joswalt
Copy link
Author

joswalt commented Oct 28, 2016

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.

@Daniel15
Copy link
Member

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% :)

@joswalt
Copy link
Author

joswalt commented Oct 28, 2016

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.

@Daniel15
Copy link
Member

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.

@joswalt
Copy link
Author

joswalt commented Oct 28, 2016

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.

@Daniel15
Copy link
Member

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?

@joswalt
Copy link
Author

joswalt commented Oct 28, 2016

This does help. I had encountered my original issue trying to install the angular-cli globally to be able to scaffold new projects.

@rwxrob
Copy link

rwxrob commented Nov 25, 2016

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.

@alayek
Copy link

alayek commented Nov 28, 2016

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.

@rwiechert
Copy link

rwiechert commented Dec 26, 2016

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)

@elishnevsky
Copy link

Looks like it is still an open issue. Any progress on it?

@ghost
Copy link

ghost commented Mar 22, 2017

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.

@RunningV
Copy link

check yarn global bin on CLI, then copy the path to add the global environment path.

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

No branches or pull requests

8 participants