ng serve 命令不起作用 angular 5 [英] ng serve command not working angular 5
问题描述
如果我运行 ng serve,就会出现这个错误
If I run ng serve, getting this error
ng :术语ng"不被识别为 cmdlet、函数、脚本文件或可运行程序的名称.检查名称的拼写,或如果包含路径,请验证路径是否正确,然后重试.在行:1 字符:1+ ng 服务+ ~~+ CategoryInfo : ObjectNotFound: (ng:String) [], CommandNotFoundException+ FullQualifiedErrorId : CommandNotFoundException
ng : The term 'ng' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + ng serve + ~~ + CategoryInfo : ObjectNotFound: (ng:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
我试过 npm run ng serve,遇到这个错误
I have tried npm run ng serve, getting this error
找不到本地工作区文件 ('angular.json').错误:找不到本地工作区文件 ('angular.json').在 WorkspaceLoader._getProjectWorkspaceFilePath (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\workspace-loader.js:37: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:32)在服务命令.(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 错误!错误号 1npm 错误!npv2@0.0.0 ng: ng "serve"
npm 错误!退出状态 1npm 错误!npm 错误!在 npv2@0.0.0 ng 脚本中失败.npm 错误!这可能不是 npm 的问题.上面可能有额外的日志输出.
Local workspace file ('angular.json') could not be found. Error: Local workspace file ('angular.json') could not be found. at WorkspaceLoader._getProjectWorkspaceFilePath (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\workspace-loader.js:3 7:19) at WorkspaceLoader.loadWorkspace (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\workspace-loader.js:24:21) at ServeCommand._loadWorkspaceAndArchitect (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:180:3 2) at ServeCommand. (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:47:25) at Generator.next () at C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:7:71 at new Promise () at __awaiter (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:3:12) at ServeCommand.initialize (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:46:16) at Object. (C:\Users\rohit\AppData\Roaming\npm\node_modules\@angular\cli\models\command-runner.js:87:23) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! npv2@0.0.0 ng:
ng "serve"
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the npv2@0.0.0 ng script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
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 并清除了缓存,再次安装但面临同样的问题.
I have uninstall @angular/cli and cleared the cached, again installed but facing same issue.
请提出建议.
推荐答案
这可能是由于不同版本的 angular-cli.检查 angular-cli 的版本,你应该没有版本 6,而是使用 1.7.原因在 angular 6 中,配置在 angular.json 文件中.在 1.7 版中,配置位于 angular-cli.json
This could be due to different versions of angular-cli. Check the version of angular-cli, you should not have version 6, but use 1.7. Cause in angular 6 the configuration is in angular.json file. In version 1.7 the configuration is in angular-cli.json
这篇关于ng serve 命令不起作用 angular 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!