2

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.

mjck
  • 187
  • 3
  • 5
  • 18
  • It gave error because you installed latest version of Angular CLI and your project built with may be older version of angular Try to run: npm install -g @angular/cli@1.7.4 – Parth Savadiya Jun 12 '18 at 07:07
  • Thanks for reponse, I tried this but facing same issue – mjck Jun 12 '18 at 07:09
  • `npm i -g @angular/cli`, or if it's installed locally, try running `npm run serve` after you added `"serve": "ng serve"` to your package file –  Jun 12 '18 at 07:10
  • From which path you are trying to run? that path contain package.json and angular.json file? – Parth Savadiya Jun 12 '18 at 07:11
  • where I can see the path or update – mjck Jun 12 '18 at 07:20

4 Answers4

4
> npm start

will solve your problem as it solved mine

Kondas Lamar Jnr
  • 143
  • 1
  • 11
2

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

alexKhymenko
  • 5,450
  • 23
  • 40
  • 1
    This should be a comment –  Jun 12 '18 at 07:11
  • Thanks for the update, I have installed npm install -g @angular/cli@1.7.4, removed the node modules folder and installed it again. if I run npm run ng serve its working fine, but if I run ng serve its not working – mjck Jun 12 '18 at 07:54
  • I challenge this solution. If we look at the documentation and other online articles, angular-cli 1.7 contains vulnerabilities, due to which latest version of angular-cli is preferred. Answer is Okay if you are not putting something in production. – Sudhir Kaushik Dec 08 '18 at 17:26
0

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`
Dulanga Heshan
  • 1,335
  • 1
  • 19
  • 36
-1

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

Arne
  • 832
  • 1
  • 5
  • 13