Created by: AriPerkkio
Fixes #10403. This PR speeds up npx create-react-app
by six minutes when run behind a corporate proxy.
What:
NPM has a bug where it acts really slow when run via child_process
in an environment behind corporate proxy. Similar issues:
- https://github.com/prettier/prettier-vscode/issues/1143
- https://github.com/microsoft/vscode-languageserver-node/issues/551
Likely caused by https://github.com/sindresorhus/got/issues/79.
With current version of CRA it takes 6 minutes additional time when npx create-react-app
is run.
Use this to test whether your environment is affected:
node -e "console.log(require('child_process').execSync('npm --version', { env: { ...process.env, NO_UPDATE_NOTIFIER: undefined }}).toString())"
This command takes 3 minutes to run in such environments.
How:
There is a work-around . If NO_UPDATE_NOTIFIER
is available as environment variable npm internally skips some checks and moves on. Setting this variable "true"
is something I always do to my work machines - but CRA cannot expect all developers to do this manually.
https://github.com/yeoman/update-notifier/blob/master/index.js#L43
This PR adds NO_UPDATE_NOTIFIER
to those require('child_process').execSync('npm ...')
calls.
Link to child_process docs for busy people
Test Plan:
As this can only be reproduced when in environment behind corporate proxy this cannot be tested easily. I tested this manually in such environment. Debug logs are wrapped around these lines:
Without the fix:
$ node index.js repro-app
Checking version [15:16:21]
> execSync('npm view create-react-app version');
Version 4.0.1 Time [15:19:29]
Creating a new React app in <removed>
Installing packages. This might take a couple of minutes.
Getting proxy [15:19:30]
> execSync('npm config get https-proxy');
Got proxy true Time [15:22:39]
With the fix:
$ node index.js fixed-app
Checking version [15:50:52]
> execSync('npm view create-react-app version', { env: { NO_UPDATE_NOTIFIER: 'true' }});
Version 4.0.1 Time [15:50:54]
Creating a new React app in <removed>
Installing packages. This might take a couple of minutes.
Getting proxy [15:50:54]
> execSync('npm config get https-proxy', { env: { NO_UPDATE_NOTIFIER: 'true' }});
Got proxy true Time [15:50:55]
All comments are welcome.