ng serve command not working angular 5

百般思念 提交于 2019-12-11 06:34:39

问题


If I run ng serve, getting this error

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

I have tried npm run ng serve, getting this error

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

I have uninstall @angular/cli and cleared the cached, again installed but facing same issue.

Kindly suggest.


回答1:


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




回答2:


This may work

add your your npm folder path and angular-cli\bin folder path to environment variables

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



回答3:


> npm start

will solve your problem as it solved mine




回答4:


You have two issues here. You are trying to run global angular-cli commands without having the angular cli globally installed. You could solve this by installing the CLI globally using npm i -g @angular/cli The next issue you have is that when using the project angular cli, you upgraded the cli but not the project itself. You can either reinstall an older cli by changing the version in your package.json, or upgrade your package using the awesome new schematics. For this I'd advise you to read the upgrade guide.

If you don't feel like reading, and feel especially lucky today, you can just download the 6.0 cli globally in the way mentioned above, and run ng update



来源:https://stackoverflow.com/questions/50811124/ng-serve-command-not-working-angular-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!