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

Angular 17新项目运行异常求助:NG0203错误排查

解决Angular 17 NG0203错误的实操步骤
  • 清理项目依赖与缓存

    1. 先关掉正在运行的ng serve进程
    2. 执行命令删除旧依赖和锁文件:
      # Mac/Linux环境
      rm -rf node_modules package-lock.json
      npm cache clean --force
      
      # Windows环境
      rmdir /s /q node_modules
      del package-lock.json
      npm cache clean --force
      
    3. 重新安装依赖:npm install
  • 对齐Angular CLI版本
    运行ng version查看本地CLI版本,确保和项目的17.0.8一致。如果版本不匹配,全局安装对应版本:

    npm install -g @angular/cli@17.0.8
    
  • 确认main.ts代码合规
    打开项目根目录的main.ts,确保是Angular 17默认的启动代码,不要在非注入上下文里调用inject():

    import { bootstrapApplication } from '@angular/platform-browser';
    import { appConfig } from './app/app.config';
    import { AppComponent } from './app/app.component';
    
    bootstrapApplication(AppComponent, appConfig)
      .catch((err) => console.error(err));
    
  • 重启服务并清浏览器缓存

    1. 重新启动ng serve
    2. 打开浏览器后按Ctrl+Shift+R(Windows/Linux)或Cmd+Shift+R(Mac)强制刷新,清除浏览器缓存

内容的提问来源于stack exchange,提问作者Frunobulax

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 19:12:07