本文介绍了我收到此错误:当我尝试从Linux使用ng serve运行我的应用程序时找不到模块'@angular-devkit/build-angular/package.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,当我尝试从终端(linux)运行我的应用程序时,出现以下错误:

hello guys I have this next error when I try run my App from the terminal(linux), when I run this command:

然后我在终端中收到此错误:

and I get this error in my terminal:

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-devkit/build-angular/package.json'

这部分说找不到名为'@ angular-devkit/build-angular/package.json'"的模块

this part say that cannot find moduled called: "'@angular-devkit/build-angular/package.json'"

然后我在项目中检查了这个文件,但是我有这个,看:

then I cheked out this file in my project but I have this, look:

  "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"
  }

然后我去了google进行搜索,我从,我尝试了他们的解决方案,但是它不起作用,我再次运行ng serve命令.

then i went to google and search and I found this like from stackoverflow and I tried their solution but it does not work and I run the command ng serve again.

我做错了什么?

之前,在我添加3个组件之前:使用以下命令在我的文件夹 src/app 中添加登录,注册和主页: ng生成组件登录,然后导入我文件中的组件:app.component.ts这样:

before nothing , before I added 3 components: login,register and home in my folder : src/app with this command : ng generate component login and I import my component in my file : app.component.ts this way:

/* 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';
}

也许这是一部分,但是我找不到解决方案,任何角度专家都可以告诉我我做错了什么?

maybe is this part but I dont find a solution, any expert in angular could tell me what I did wrong?

更新

我正在google中继续搜索,发现了这一点: github/Angular 他们说我会安装npm/angular-cli/node再次运行此命令以更新我的角度cli:

I am continue searching in google and I found this:github/Angular they are saying that I would install npm/angular-cli/node again and I run this command for update my angular cli:

但是首先我使用以下命令更新我的npm:

but first i update my npm with this command:

但是它仍然不起作用.

推荐答案

请尝试将npm安装在项目文件夹中.我已经在全球范围内安装了npm,但是再次将npm安装在解决方案文件夹中解决了我的问题.

Please try installing the npm on a project folder. I had installed npm globally but installing the npm once again on a solution folder fixed my issue.

npm install 可以解决问题.然后 ng服务-o

npm install in the project folder will do the trick. Then do ng serve -o

这篇关于我收到此错误:当我尝试从Linux使用ng serve运行我的应用程序时找不到模块'@angular-devkit/build-angular/package.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 04:34