rush pickup the wrong `.npmrc` when invoked via npm
Steps to reproduce:
- Clone this repo: https://github.com/xbtsw/rush-npmrc-problem
npm install --registry https://registry.npmjs.org/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.
Thanks for reporting this. We'll investigate it and follow up.
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
dependencieslist. - 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
(Also thanks for the repro -- it made this super easy to investigate.)
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.
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 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 this issue is closed. Could you create a new issue with current repro steps?
@octogonz created #2817