Error: This command is not available when running the Angular CLI outside a workspace in Angular

If you are new to Angular application development and if you run ng serve command out side of your Angular root directory you will get Error: This command is not available when running the Angular CLI outside a workspace error.

For example let’s create an new Angular application inside a folder called Angular Applications.

Open your command prompt or terminal and run ng new command to create the new Angular application.

D:\Angular Applications>ng new shoppingapp  

It will create a new folder called shoppingapp and that folder contains our Angular source code.

Now D:\Angular Applications\shoppingapp is our Angular project root directory.

You have to navigate to project root directory and then you have to run ng serve.

D:\Angular Applications> cd shoppingapp

D:\Angular Applications\shoppingapp>ng serve

Most of the newbie Angular developers won’t navigate to Angular root directory, after creating the application.

And runs the command in the parent folder. In that case they will get Error: This command is not available when running the Angular CLI outside a workspace error.

To avoid Error: This command is not available when running the Angular CLI outside a workspace you should always run ng serve command in Angular root directory.

Our Angular root directory contains Angular CLI configuration file i.e, angular.json file.

ng serve command try to look for this configuration file while executing the command. If there is no angular.json file it will return error.

If you delete the angular.json file or If you rename to other name you will get the same error.

So be careful while doing any changes to the files generated by Angular CLI.

Avatar

Arunkumar Gudelli

Liked this post? Subscribe
Next
Previous