React项目安装失败求助:Yarn网络连接错误排查
Hey there! Let's break down why your React project setup with Yarn is hitting a wall. From the error logs you shared, the core issue is obvious: Yarn is trying to use a local proxy (127.0.0.1:80) that it can't connect to, which is blocking it from pulling React packages from the registry.
Here's a step-by-step fix guide to get you back on track:
Step 1: Check and Clear Yarn's Proxy Configurations
First, let's confirm if Yarn has misconfigured proxy settings causing the problem:
- Run these commands in your terminal to check current proxy configs:
yarn config get proxy yarn config get https-proxy - If either command returns
http://127.0.0.1:80or any unexpected proxy address, delete those settings right away:yarn config delete proxy yarn config delete https-proxy
Step 2: Verify System-Level Proxy Settings
Yarn automatically inherits proxy settings from your operating system. If you've set up a system-wide proxy (like in Windows' Internet Options or macOS's Network settings):
- Temporarily disable the proxy to rule out connectivity issues.
- If you need the proxy active, double-check that the proxy address and port are correct, and the proxy service is actually running.
Step 3: (Optional but Recommended) Switch to a Domestic Registry
Even if proxy issues are fixed, connecting to the official Yarn registry can be slow from some regions. Switching to a domestic mirror can prevent future network-related failures:
yarn config set registry https://registry.npmmirror.com
Step 4: Re-Run the Installation Command
After completing the above steps, try running your original install command again:
yarn add --exact react react-dom react-scripts cra-template --cwd D:\React\resort
Extra Checks If the Problem Persists
- Firewall/Antivirus Interference: Some security software might block Yarn's network requests. Temporarily disable your firewall or antivirus and try again to see if that's the culprit.
- Port 80 Occupancy: The error mentions a connection refused on port 80. Use
netstat -ano | findstr ":80"on Windows to check if another program is using this port, and stop that program if needed. - Dig Into the Error Log: The
yarn-error.logfile atD:\React\resort\yarn-error.logmight have more detailed clues if the above steps don't resolve the issue.
内容的提问来源于stack exchange,提问作者NANA

