您似乎不依赖“@angular/core”。这是一个错误

您似乎不依赖“@angular/core”。这是一个错误

运行 Angular 4 项目时出现以下错误。

you seem to not be depending on "@angular/core". This is an error.

详细说明请参见下图:

当前版本:Angular Cli:1.7.3 Node:8.10.0

在此处输入图片描述

我尝试过这个选项:

rm -rf node_modules
rm package-lock.json
npm install

运行上述命令时出现以下错误:

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN @angular/[email protected] requires a peer of @angular/core@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/[email protected] requires a peer of @angular/common@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/[email protected] requires a peer of @angular/core@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/[email protected] requires a peer of @angular/common@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @ng-bootstrap/[email protected] requires a peer of @angular/core@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN @ng-bootstrap/[email protected] requires a peer of @angular/common@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN @ng-bootstrap/[email protected] requires a peer of @angular/forms@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN @angular-devkit/[email protected] requires a peer of @angular-devkit/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN @schematics/[email protected] requires a peer of @angular-devkit/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

答案1

我通过运行以下命令得到了解决方案:

删除你的节点模块,检查你的 package.json 文件是否包含 @angular/core 然后用它重新安装 npm i

相关内容