Skip to content

Conversation

AriPerkkio
Copy link

@AriPerkkio AriPerkkio commented Jan 22, 2021

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:

Likely caused by sindresorhus/got#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:

return execSync('npm view create-react-app version').toString().trim();

let httpsProxy = execSync('npm config get https-proxy').toString().trim();

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. 👍

@stale
Copy link

stale bot commented Jan 9, 2022

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jan 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

checkLatestVersion fails when behind a corporate proxy
2 participants