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 doesn't use .npmrc from $HOME when run as root #3920

Closed
also opened this issue Jul 12, 2017 · 8 comments
Closed

yarn doesn't use .npmrc from $HOME when run as root #3920

also opened this issue Jul 12, 2017 · 8 comments

Comments

@also
Copy link

also commented Jul 12, 2017

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

Bug; incompatibility with npm.

What is the current behavior?

When run as the root user on Linux, yarn does not use $HOME/.npmrc but uses /usr/local/share/.npmrc instead.

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

https://github.com/yarnpkg/yarn/blob/v0.28.2/src/util/user-home-dir.js#L8
https://github.com/yarnpkg/yarn/blob/v0.28.2/src/registries/npm-registry.js#L132

Run yarn config list --verbose as root on Linux (while not in any subdirectory of$HOME) and observe that yarn looks for .npmrc first in the current directory, then in /usr/local/share/, but never in $HOME (/root).

What is the expected behavior?

Yarn defaults to $HOME/.npmrc as documented by npm.

A module named user-home-dir doesn't export a string which isn't the user's home directory.

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

yarn v0.27.5
node v8.1.3

@also also changed the title yarn does use .npmrc from $HOME when run as root yarn doesn't use .npmrc from $HOME when run as root Jul 12, 2017
@dylanfoster
Copy link

dylanfoster commented Jul 12, 2017

It looks like it doesn't use ./.npmrc either. I had to downgrade to get it to work

@vinicius73
Copy link

Same problem here

image

@BYK
Copy link
Member

BYK commented Jul 19, 2017

Thanks for reporting. Anyone willing to submit a PR for this?

@kaylie-alexa kaylie-alexa self-assigned this Jul 20, 2017
@BYK
Copy link
Member

BYK commented Jul 28, 2017

@kaylieEB still working on this?

@kaylie-alexa
Copy link
Member

hey @BYK sorry for the delay, here it is :) #4047

@BYK
Copy link
Member

BYK commented Jul 29, 2017

@kaylieEB no worries, just wanted to make sure to avoid duplicate work :)

BYK pushed a commit that referenced this issue Jul 31, 2017
**Summary**
Fix for #3920.

In this [commit](https://github.com/wtgtybhertgeghgtwtg/yarn/commit/f4fe7431ed992862a1c1d2357e6521c268bad7a7), `userHome` for linux users running as root was changed to `/usr/local/share`, mainly to allow for other users to run globally added bins. However this introduced a bug where npmrc wasn't being looked in the root directory after checking `/user/local/share`. So this change pushes another location to check in case `userHome` is different from native home directory returned by `os.homedir()`

**Test plan**
I've added a test to generally test the `getPossibleConfigLocations` method, but I haven't been able to properly mock out running it as a root user on linux. Suggestions welcome!
@Jessevanbekkum
Copy link

We also had this problem, and we were able to solve it by placing the .npmrc in the directory next to the git repository (one directory up from the source dir). Then yarn was able to pick up the .npmrc. Not a pretty solution, but it worked

@BYK
Copy link
Member

BYK commented Aug 10, 2017

Oh, looks like we forgot to close this. This is fixed on master.

@BYK BYK closed this as completed Aug 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants