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

运行Angular项目时提示未依赖@angular/core错误的解决方法

解决Angular项目报错:You seem to not be depending on "@angular/core". This is an error.
  • 安装@angular/core依赖:在项目根目录执行对应包管理工具的安装命令
    npm用户执行:

    npm install @angular/core --save
    

    yarn用户执行:

    yarn add @angular/core
    
  • 校验依赖版本一致性:打开项目根目录的package.json文件,检查dependencies字段下是否存在@angular/core,且其版本号与其他Angular核心包(如@angular/common、@angular/compiler)保持一致。若版本不匹配,执行指定版本安装命令,例如项目使用Angular 16时:

    npm install @angular/core@16 --save
    
  • 清除缓存并重装依赖:若安装后报错仍存在,执行以下操作重置依赖环境

    npm cache clean --force
    rm -rf node_modules package-lock.json
    npm install
    

    Windows系统需手动删除node_modules文件夹和package-lock.json文件后,再执行npm install。

  • 检查Angular CLI兼容性:执行ng version查看CLI版本,确保其与项目Angular核心包版本匹配,版本差异过大时需同步更新CLI或项目依赖版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 21:45:37