【问题标题】:NG SERVE command issueNG SERVE 命令问题
【发布时间】:2019-06-04 20:52:51
【问题描述】:

我在通过 ng serve 运行我的 Angular 应用程序时遇到问题。

经过数小时与 Angular 的斗争(与 Angular cli 有很多问题),我能够生成项目而不会出错。我将此项目导入 IntelliJ 并希望通过 ng serve 命令运行。

在调用 ng serve 后得到这个: 当前未安装程序“ng”。您可以通过键入以下内容来安装它: sudo apt install ng-common

有什么想法吗?

【问题讨论】:

  • 你说你成功生成了一个项目,你是用ng generate做的吗?如果你这样做了,那么ng serve 也没有理由不工作。检查您当前的 Node 安装是否安装了 @angular/cli。如果没有,请重新安装:npm i -g @angular/cli,然后再试一次。
  • 我确实使用过:ng new TestApp 项目已生成。在此之后,我想运行ng serve 并得到这个The program ng is currently not installed. You can install it by typing: sudo apt install ng-common。下班后我会检查您的解决方案并通知您。
  • @derirative23 是您全局安装的 Angular CLI
  • @Shashank Vivek 我想我用 'npm install -g @angular/cli' 安装了 angular CLI。但是如果没有全局安装,我将能够通过“ng new TestApp”创建项目,但我遇到了权限问题,我尝试用 ~/.profil 做一些事情,但我现在不确定。下班后我会检查你的解决方案并通知你

标签: javascript angular configuration frontend


【解决方案1】:

希望本指南能帮助您创建一个没有错误的项目。

1. first open terminal or console window and run, npm install -g @angular/cli
2. To create a new workspace and initial starter app, ng new my-app-name
3. Go to my-app-name folder, cd my-app-name
4. Launch the server by using the CLI command, ng serve --o (--o to open in browser)

【讨论】:

  • 所以它解决了我的问题,但我还需要手动更改 npm 的默认目录链接如下 [link] (docs.npmjs.com/…) 感谢您的帮助
【解决方案2】:

确保您从 Angular 项目的根目录中运行“ng serve”命令(cli 路径正确)。

发生此错误是因为您的命令行界面无法理解该命令,而“ng new project”几乎可以从任何地方执行,而其他 ng 命令(例如“ng serve”)只能从项目根目录中执行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    • 2021-08-07
    • 2021-08-04
    • 2021-08-05
    • 2018-11-21
    • 2021-10-25
    • 1970-01-01
    相关资源
    最近更新 更多