【问题标题】:ng serve command not working angular 5ng serve 命令不起作用 角度 5
【发布时间】:2018-11-21 11:52:20
【问题描述】:

如果我运行 ng serve,就会出现这个错误

ng :术语“ng”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或 如果包含路径,请验证路径是否正确并重试。 在行:1 字符:1 + ng服务 + ~~ + CategoryInfo : ObjectNotFound: (ng:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

我尝试了 npm run ng serve,得到这个错误

找不到本地工作区文件 ('angular.json')。 错误:找不到本地工作区文件('angular.json')。 在 WorkspaceLoader._getProjectWorkspaceFilePath (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\workspace-loader.js:3 7:19) 在 WorkspaceLoader.loadWorkspace (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\workspace-loader.js:24:21) 在 ServeCommand._loadWorkspaceAndArchitect (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:180:3 2) 在ServeCommand。 (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:47:25) 在 Generator.next () 在 C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:7:71 在新的承诺 () 在 __awaiter (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:3:12) 在 ServeCommand.initialize (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:46:16) 在对象。 (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\command-runner.js:87:23) npm 错误!代码生命周期 npm 错误!错误号 1 npm 错误! npv2@0.0.0 ng:ng "serve" npm 错误!退出状态 1 npm 错误! npm 错误!在 npv2@0.0.0 ng 脚本中失败。 npm 错误!这可能不是 npm 的问题。上面可能还有额外的日志输出。

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\rohit\AppData\Roaming\npm-cache\_logs\2018-06-12T06_59_12_392Z-debug.log

我卸载了@angular/cli 并清除了缓存,再次安装但面临同样的问题。

请推荐。

【问题讨论】:

  • 它给出了错误,因为您安装了最新版本的 Angular CLI,并且您构建的项目可能是旧版本的 angular 尝试运行:npm install -g @angular/cli@1.7.4
  • 感谢回复,我试过了,但遇到同样的问题
  • npm i -g @angular/cli,或者如果它已安装在本地,请在将"serve": "ng serve" 添加到您的包文件后尝试运行npm run serve
  • 您尝试从哪个路径运行?该路径包含 package.json 和 angular.json 文件?
  • 哪里可以看到路径或更新

标签: angular angular5 angular-cli


【解决方案1】:

这可能是由于 angular-cli 的不同版本造成的。 检查 angular-cli 的版本,你不应该有版本 6,而是使用 1.7。 因为在 Angular 6 中,配置位于 angular.json 文件中。在 1.7 版本中,配置位于 angular-cli.json

【讨论】:

  • 这应该是一条评论
  • 感谢更新,我已经安装了 npm install -g @angular/cli@1.7.4,删除了节点模块文件夹并重新安装。如果我运行 npm run ng serve 它工作正常,但如果我运行 ng serve 它不工作
  • 我挑战这个解决方案。如果我们查看文档和其他在线文章,angular-cli 1.7 包含漏洞,因此首选最新版本的 angular-cli。如果您没有将某些东西投入生产,答案是好的。
【解决方案2】:
> npm start

将解决您的问题,因为它解决了我的问题

【讨论】:

  • 为我工作。谢谢
【解决方案3】:

这可能有效

添加您的 npm 文件夹路径和 angular-cli\bin 文件夹路径 到环境变量

C:\Users\YourPcName\AppData\Roaming\npm`
C:\Users\YoutPcName\AppData\Roaming\npm\node_modules\angular-cli\bin`

【讨论】:

    【解决方案4】:

    这里有两个问题。您正在尝试在未全局安装 angular cli 的情况下运行全局 angular-cli 命令。您可以通过使用全局安装 CLI 来解决此问题 npm i -g @angular/cli 您遇到的下一个问题是,在使用项目 angular cli 时,您升级了 cli,但没有升级项目本身。您可以通过更改 package.json 中的版本来重新安装旧的 cli,或者使用很棒的新原理图升级您的包。为此,我建议您阅读upgrade guide

    如果你不喜欢看书,今天特别幸运,你可以按照上面提到的方式在全局下载6.0 cli,然后运行ng update

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      • 2016-11-24
      • 2014-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多