Angular 10在Windows 10下无法运行,执行ng serve时出错求助
ng serve Errors on Windows 10 Hey there! Let’s work through this Angular 10 issue together. Since I can’t see the error screenshot you mentioned, I’ll share the most common solutions that resolve ng serve failures on Windows 10—these fix most cases:
Clean up dependencies and cache
First, wipe out old dependencies and cached data that might be corrupted:- Delete the
node_modulesfolder and lock file in your project:rmdir /s node_modules del package-lock.json - Reinstall fresh, uncorrupted dependencies:
npm install - Clear Angular’s global cache to eliminate stale build data:
ng cache clean --force
- Delete the
Verify Node.js version compatibility
Angular 10 strictly requires Node.js versions between 12.x and 14.x (it doesn’t support 15+). Check your current version with:node -vIf it’s outside this range, install a compatible LTS version (Node 14 works perfectly for Angular 10) and retry.
Repair Angular CLI installation
Outdated or mismatched CLI versions are a frequent culprit. Fix this by:- Uninstall the global CLI to remove any broken instances:
npm uninstall -g @angular/cli - Reinstall the Angular 10-specific CLI globally:
npm install -g @angular/cli@10.x.x - Sync your local project’s CLI version to match the global one:
npm install --save-dev @angular/cli@10.x.x
- Uninstall the global CLI to remove any broken instances:
Check for port conflicts
The defaultng serveport (4200) might be used by another app (like a local server or background service). Try running on a different port:ng serve --port 4201Or find and kill the process using port 4200 with:
netstat -ano | findstr :4200Then use Task Manager to end the process with the matching PID.
Temporarily disable security tools
Windows Defender or third-party antivirus/firewall software sometimes blocks Angular’s file access during builds. Turn these off temporarily and runng serveto test if that resolves the issue.Validate project configuration files
Double-check your core config files for typos or incompatible settings:- Ensure the
architect > servesection inangular.jsonhas no path errors or invalid options. - Confirm
tsconfig.jsonsetstargettoES2015orES2016(the compatible versions for Angular 10).
- Ensure the
If none of these work, please share the exact error text from your terminal (copy-paste the key lines)—that will help me pinpoint the exact problem!
内容的提问来源于stack exchange,提问作者Emy

