You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular项目执行ng serve报错:找不到@angular-devkit/build-angular模块

Troubleshooting "Could not find module '@angular-devkit/build-angular'" in Angular 6 Project

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 frontend folder:
    npm ci
    

4. Full Cleanup and Reinstall

If the above steps don't work, perform a thorough reset:

  • Delete the node_modules folder and lock files in your frontend directory:
    # 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:23:38