求助:使用ng new创建Angular项目时npm 5.8.0报错,启动旧项目也异常
Hey there, let's work through this issue together. Based on your environment details (Node v8.11.1, npm v5.8.0, Angular CLI v6.0.0) and the fact that problems popped up suddenly—even affecting existing projects—here are actionable fixes to try:
Common Fixes to Try
1. Clear the npm Cache
Corrupted cache files are one of the most frequent causes of random npm/Angular CLI errors. Let's reset it:
npm cache clean --force
After running this, attempt to create a new Angular project again.
2. Reinstall the Angular CLI Globally
Your global Angular CLI installation might have become corrupted somehow. Let's uninstall and reinstall the exact version you're using to avoid compatibility mismatches:
npm uninstall -g @angular/cli npm install -g @angular/cli@6.0.0
3. Update npm to a Compatible Version
npm 5.8.0 has some known bugs, and it pairs better with Node 8.11.1 when using npm 6.x (the latest stable branch compatible with Node 8). Update npm with:
npm install -g npm@6.14.18
4. Fix Existing Project Dependencies
For your existing projects throwing errors, corrupted node_modules or lock files are often the culprit. Follow these steps:
- Delete the
node_modulesfolder andpackage-lock.jsonfile - Refresh dependencies with:
npm install
5. Check Permissions
Permission issues can block npm from installing packages properly:
- On macOS/Linux: Try running commands with
sudo(or fix your npm permissions long-term to avoid needing sudo) - On Windows: Launch your terminal as Administrator before executing commands
6. Rule Out Network/Proxy Issues
If your network changed recently or you're behind a proxy, npm might fail to download packages. Test basic connectivity with:
npm install lodash
If this fails, check your network settings or disable proxies temporarily.
Final Notes
Since this started suddenly without changes to your environment, the most likely fixes are clearing the cache or reinstalling the Angular CLI. Start with those two first—they resolve most cases like this.
内容的提问来源于stack exchange,提问作者SMPLYJR

