Create-react-app在一台Windows设备安装卡顿,另一台正常求助
npx create-react-app Installation on Windows Hey there, sorry to hear you're hitting this roadblock with create-react-app on one of your Windows machines. Since it works fine on another device, the issue is likely specific to the problematic machine's environment. Let’s walk through some targeted fixes that should get you past that stuck Installing react, react-dom, and react-scripts with cra-template... step:
Clear npm and npx caches
Corrupted cache files are a frequent culprit here. Run these commands in your terminal (as administrator if possible):npm cache clean --force npx clear-npx-cacheOnce done, retry the original command:
npx create-react-app newTemporarily disable antivirus/firewall
Windows Defender or third-party security tools sometimes flag npm’s network requests as suspicious and block them, causing the installation to hang. Try turning off your antivirus/firewall temporarily, then run the create-react-app command again. Don’t forget to re-enable them afterward!Switch to a faster npm registry
If the issue is network-related (slow or blocked access to the default npm registry), switch to a mirror like the npmmirror registry:npm config set registry https://registry.npmmirror.comThen retry the installation command. If you need to switch back later, run:
npm config set registry https://registry.npmjs.org/Manually create the project (bypass npx auto-install)
If the above steps don’t work, let’s build the project from scratch manually:- Create and navigate to your project folder:
mkdir new && cd new - Initialize npm:
npm init -y - Install the required dependencies directly:
npm install react react-dom react-scripts cra-template - Open your
package.jsonfile and replace the defaultscriptssection with this:"scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" } - Create
publicandsrcfolders in your project root. You can copy the default template files from your working Windows machine (the one where create-react-app works) or use basic placeholder files like the standard CRA HTML template forpublic/index.htmland default component files forsrc.
- Create and navigate to your project folder:
Check user permissions and run terminal as admin
Sometimes the installation gets stuck because your user account doesn’t have write access to the project directory. Try opening your terminal (Command Prompt or PowerShell) as an administrator, then run the create-react-app command again.Verify proxy settings
If your machine is on a corporate network with a proxy, npm might be having trouble connecting. Check if a proxy is configured with:npm config get proxy npm config get https-proxyIf you see proxy URLs here but don’t need them (or they’re incorrect), clear them with:
npm config delete proxy npm config delete https-proxyIf you do need a proxy, set it correctly with your network’s proxy details:
npm config set proxy http://your-proxy-address:port npm config set https-proxy http://your-proxy-address:port
Give these steps a try one by one—odds are one of them will resolve the stuck installation issue for you.
内容的提问来源于stack exchange,提问作者Vinkal Chandel

