运行ng new project-1时出现Package安装失败及Schematic工作流错误的技术求助
Hey there, sorry to hear you're hitting this snag while trying to spin up a new Angular project! Let's work through some practical fixes that often resolve this error, even after updating Node.js:
Clear the npm cache
Corrupted cache files are a super common culprit here. Run this command to wipe the cache, then retry your project creation:npm cache clean --force
After clearing, giveng new project-1another go.Update or reinstall Angular CLI
Mismatched CLI and Node.js versions can break the schematic workflow. First, check your current CLI version withng version. If it's not up to date:- Uninstall the global CLI:
npm uninstall -g @angular/cli - Install the latest stable version:
npm install -g @angular/cli@latest
Note: On Windows, make sure you run Command Prompt as Administrator for these steps to avoid permission issues.
- Uninstall the global CLI:
Switch to a different package manager
Sometimes npm struggles with pulling dependencies—give Yarn a shot instead:- Install Yarn globally if you haven't already:
npm install -g yarn - Create the project using Yarn:
ng new project-1 --package-manager yarn
- Install Yarn globally if you haven't already:
Check network & registry settings
Network restrictions or slow connections can derail package downloads. Try switching to a faster, more reliable registry (like the npm mirror) with:npm config set registry https://registry.npmmirror.com
Then retry creating the project.Opt for manual project setup
If the automated schematic keeps failing, build the project step-by-step:- Create a folder and navigate into it:
mkdir project-1 && cd project-1 - Initialize npm:
npm init -y - Install Angular core dependencies:
npm install @angular/core @angular/cli - Initialize the Angular project structure:
ng init
- Create a folder and navigate into it:
Downgrade Node.js to an LTS version
While you installed the latest Node.js, cutting-edge versions sometimes have compatibility gaps with Angular. Try switching to an LTS (Long-Term Support) version like 18.x or 20.x—uninstall your current Node.js, download the LTS build from the official site, and reinstall.
If none of these steps work, share the full error output you get when running ng new project-1 (the lines above the "Package install failed" message)—that will help pinpoint exactly what's going wrong.
内容的提问来源于stack exchange,提问作者Anjana Pathirana

