rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

rush pickup the wrong `.npmrc` when invoked via npm

Open ccstr opened this issue 8 years ago • 8 comments

Steps to reproduce:

  1. Clone this repo: https://github.com/xbtsw/rush-npmrc-problem
  2. npm install --registry https://registry.npmjs.org/
  3. npm run generate

Expected behavior:

rush should use common/config/rush/.npmrc when installing npm and project dependencies.

Actual behavior:

rush used ./.npmrc instead.

Notes:

This project is a hypothetical setup, this problem is especially evident when using private registry with auth.

ccstr avatar Apr 24 '18 18:04 ccstr

Thanks for reporting this. We'll investigate it and follow up.

octogonz avatar Apr 25 '18 07:04 octogonz

This is NPM being stupid by trying to be smart: When you do npm run generate, the lifecycle wrapper apparently sets an environment variable INIT_CWD that remembers the folder where the command was invoked, in case a poorly written script changes the cwd and then tries to invoke the npm tool. When Rush performs an npm install in another folder (e.g. C:\Users\pgonzal.rush\npm-5.6.0), this environment variable causes it to look in the wrong place for .npmrc.

I will implement a fix by causing Rush to unset the INIT_CWD environment variable.

However, we can suggest some best practices that would avoid this issue:

  • Don't put a package.json file in the root folder of your repo. The problem is it will install a node_modules folder there, which can be discovered during module resolution, undoing Rush's protection against projects that accidentally import libraries that aren't in their dependencies list.
  • If you want a nice way to automatically install Rush, we suggest something like InstallRushOnlyIfNeeded.js. In the future we'll provide an official pattern for bootstrapping Rush.
  • Don't use NPM to invoke Rush commands. Just use the Rush command directly.
  • We are now recommending to use PNPM instead of NPM if possible

CC @nickpape-msft @iclanton

octogonz avatar Apr 25 '18 17:04 octogonz

(Also thanks for the repro -- it made this super easy to investigate.)

octogonz avatar Apr 25 '18 17:04 octogonz

Nice suggestions about bootstrapping rush.

I am attempting to use pnpm on my project, but encountered TypeStrong/ts-loader#768 and got blocked on that front.

ccstr avatar Apr 25 '18 18:04 ccstr

This is fixed in PR #623. It will be published initially as [email protected]. To try it you would set "rushVersion": "5.0.0-dev.7" in your rush.json.

Thanks again for reporting this issue @xbtsw !

octogonz avatar Apr 26 '18 01:04 octogonz

@octogonz I just ran into this issue with version 5.42.3 on a Mac. The project uses pnpm and running the rush commands directly work.

a-b-r-o-w-n avatar Jul 19 '21 16:07 a-b-r-o-w-n

@a-b-r-o-w-n this issue is closed. Could you create a new issue with current repro steps?

octogonz avatar Jul 19 '21 18:07 octogonz

@octogonz created #2817

a-b-r-o-w-n avatar Jul 19 '21 20:07 a-b-r-o-w-n