Angular项目执行ng serve报错:找不到@angular-devkit/build-angular模块
Let's break down how to fix this issue based on your setup and the error details:
Key Observation from Your Error
Notice that the error references C:\Users\Brandon\project-name\node_modules instead of C:\Users\Brandon\project-name\frontend\node_modules. This suggests your project might be looking for dependencies in the parent directory rather than its own node_modules folder—this is likely the root cause.
Step-by-Step Solutions
1. Fix Dependency Installation Path
First, check if there's a node_modules folder inside your frontend directory. If it's missing (and instead exists in the parent project-name folder), you probably ran npm install from the wrong directory.
Fix this by navigating directly to your project folder and running a clean install:
cd C:\Users\Brandon\project-name\frontend npm ci
Using npm ci ensures a strict, clean install that matches exactly the versions in your package-lock.json, avoiding any accidental version mismatches.
2. Ensure npm Version Compatibility for Angular 6
Angular 6 works best with npm 6.x. If you're using a newer npm version (like 7+), it can introduce compatibility issues with older Angular packages.
- Check your current npm version:
npm -v - If you're on npm 7 or higher, downgrade to npm 6:
npm install -g npm@6
Then re-run npm ci in your frontend folder.
3. Align Global and Local Angular CLI Versions
Mismatched global and local CLI versions can cause unexpected errors. Your project uses @angular/cli@6.0.3, so make sure your global CLI matches this version:
- Uninstall the global Angular CLI:
npm uninstall -g @angular/cli - Install the exact version matching your project:
npm install -g @angular/cli@6.0.3 - Reinstall local dependencies in your
frontendfolder:npm ci
4. Full Cleanup and Reinstall
If the above steps don't work, perform a thorough reset:
- Delete the
node_modulesfolder and lock files in yourfrontenddirectory:# On Windows Command Prompt rmdir /s /q node_modules del package-lock.json # On PowerShell Remove-Item -Recurse -Force node_modules Remove-Item package-lock.json - Clear the npm cache:
npm cache clean --force - Reinstall dependencies:
npm ci
5. Verify Configuration Files
Your package.json and angular.json are correctly configured for Angular 6—they reference the compatible version of @angular-devkit/build-angular and the right builders for serving/building the project. No changes are needed here unless the above steps don't resolve the issue.
After completing these steps, try running ng serve --open again—it should launch your Angular app successfully.
内容的提问来源于stack exchange,提问作者Brandon Lumsden

