【发布时间】: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