当前位置: 首页 > 知识库问答 >
问题:

我收到此错误:当我尝试从Linux使用ng服务运行我的应用程序时,找不到模块“@angular-开发工具包/构建角度/包.json

井疏珂
2023-03-14

大家好,当我尝试从终端(linux)运行我的应用程序时,当我运行此命令时,我有下一个错误:

纳服

我在我的终端中得到这个错误:

AppBlog/blog# ng serve
An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json'
Require stack:
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/index.js
- /usr/local/lib/node_modules/@angular/cli/models/architect-command.js
- /usr/local/lib/node_modules/@angular/cli/commands/serve-impl.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/index.js
- /usr/local/lib/node_modules/@angular/cli/utilities/json-schema.js
- /usr/local/lib/node_modules/@angular/cli/models/command-runner.js
- /usr/local/lib/node_modules/@angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/@angular/cli/lib/init.js
- /usr/local/lib/node_modules/@angular/cli/bin/ng
See "/tmp/ng-ev5aDi/angular-errors.log" for further details.

然后我检查了这个部分:

发生未处理的异常:找不到模块“@angular-开发工具包/构建-角度/包.json”

这部分说找不到名为“' @ angular-dev kit/build-angular/package . JSON '”的模块

然后我在我的项目中签出了这个文件,但我有这个,看:

html prettyprint-override">  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.3",
    "@angular/cli": "~9.0.3",
    "@angular/compiler-cli": "~9.0.2",
    "@angular/language-service": "~9.0.2",
    "@types/node": "^12.11.1",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~5.18.0",
    "typescript": "~3.7.5"
  }

然后我去谷歌和搜索,我发现这个像堆栈溢出,我尝试了他们的解决方案,但它不起作用,我再次运行命令ng服务。

我做错了什么?

之前没有,之前我添加了3组件:登录,注册和家在我的文件夹:src/app与此命令:ng生成组件登录和我导入我的组件在我的文件:app.component.ts这样:

/* THIS IS JUST A EXAMPLE VERY SIMILAR TO MY CODE REAL,  I just import one component*/

import { Component } from '@angular/core';
import { loginComponent } from './login.component';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  declarations: [loginComponent], //import my login
})
export class AppComponent {
  title = 'blog';
}

也许是这一部分,但我没有找到解决办法,任何专家可以告诉我,我做错了什么?

更新

我继续在google中搜索,我发现了这个:github/Angular他们说我将再次安装npm/Angural cli/node,我运行这个命令来更新我的AngularCLI:

npm卸载@angular/cli

npm 安装 -g @angular/cli@latest

但是首先我用这个命令更新我的npm:

npm install -g npm@latest

但它仍然不起作用。

共有3个答案

邢华清
2023-03-14

在我的例子中,这两个命令有帮助:

npm install -g npm@latest
npm install -g @angular/cli
刘弘新
2023-03-14

我终于找到了对我有用的东西。

在npm命令末尾添加<code>--force

npm install--save-dev@angle-devkit/build-角--force

然后< code>ng发球

焦宁
2023-03-14

请尝试在项目文件夹上安装npm。我在全局范围内安装了npm,但在解决方案文件夹上再次安装npm修复了我的问题。

项目文件夹中的< code>npm install将完成此操作。然后做好准备

 类似资料: