gpt4 book ai didi

angular - 当我尝试从 Linux 中使用 ngserve 运行我的应用程序时,出现此错误 :Cannot find module '@angular-devkit/build-angular/package. json

转载 作者:行者123 更新时间:2023-12-02 12:43:23 26 4
gpt4 key购买 nike

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

ng serve

我在终端中收到此错误:

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'”的模块

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

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

然后我去谷歌搜索,我发现这个像 stackoverflow我尝试了他们的解决方案,但它不起作用,我再次运行命令 ngserve。

我做错了什么?

之前,在我添加 3 个组件之前:在我的文件夹中添加 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';
}

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

更新

我继续在谷歌搜索,我发现了这个: github/Angular他们说我会再次安装 npm/angular-cli/node 并运行此命令来更新我的 Angular cli:

uninstalled ang-cli

npm uninstall @angular/cli

installed the latest

npm install -g @angular/cli@latest

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

installed the latest npm

npm install -g npm@latest

但是还是不行。

最佳答案

请尝试在项目文件夹中安装 npm。我已经全局安装了 npm,但在解决方案文件夹上再次安装 npm 解决了我的问题。

项目文件夹中的

npm install 就可以了。然后执行 ngserve -o

关于angular - 当我尝试从 Linux 中使用 ngserve 运行我的应用程序时,出现此错误 :Cannot find module '@angular-devkit/build-angular/package. json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60404698/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com