Last updated: Apr 4, 2024
Reading timeยท4 min
The error "This command is not available when running the Angular CLI outside
a workspace" occurs when your terminal isn't positioned in the root directory of
an Angular project when running the ng serve
command.
To solve the error, navigate to the root directory of your project (where your
angular.json
file is) and rerun the command.
ng serve --open
command while your terminal isn't located in the root directory of your Angular project.In case, you don't have an Angular project, you can create one with the following commands.
# ๐๏ธ install the `angular` CLI globally npm install -g @angular/cli@latest # ๐๏ธ create a workspace ng new my-project # ๐๏ธ run the application cd my-project ng serve --open
You can use the cd
command to change your terminal to the root directory of
your Angular project.
# ๐๏ธ list files and directories dir # ๐๏ธ make sure to replace with the name of your project cd your-angular-project ng serve --open
And here is an example of how to do it on macOS and Linux.
# ๐๏ธ list files and directories ls # ๐๏ธ make sure to replace with the name of your project cd your-angular-project ng serve --open
Alternatively, you can open your terminal directly in the root directory of your
Angular project (where your package.json
) file is located.
Here is what the root directory of your Angular project should look like. This is the directory where you should open your shell.
For example, on Windows:
Open the root directory of your Angular project (where angular.json
and
package.json
are located) in explorer.
Press Shift
and right-click in Explorer.
Click on "Open PowerShell window here".
Run the ng serve --open
command.
ng serve --open
On macOS and Linux:
angular.json
and
package.json
are located).If you don't see the "Open in terminal" option, right-click and press E
on
your keyboard.
Run the ng serve --open
command.
ng serve --open
If you don't have an Angular project, you can create one with the following commands.
# ๐๏ธ install the `angular` CLI globally npm install -g @angular/cli@latest # ๐๏ธ create a workspace ng new my-project # ๐๏ธ run the application cd my-project ng serve --open
An alternative way to solve the error is to open your terminal in your project's root directory in your IDE (e.g. Visual Studio Code).
This is what the root directory of my Angular project looks like in Visual Studio Code.
You can press CTRL + ` (Backtick) on your keyboard to open the Visual Studio code terminal.
CTRL+Shift+P
and then type "View: Toggle Terminal".Once you open the terminal in your project's root directory, run the
ng serve --open
command.
ng serve --open
An alternative approach to solve the error is to:
package.json
file).3. Click on "Open in Integrated Terminal" as shown in the gif above.
ng serve --open
command.ng serve --open
Make sure to right-click on the folder that contains your Angular project (the
one that contains the package.json
file).
I opened the root directory of my Angular project in VSCode, so I clicked directly in the left sidebar.
You can learn more about the related topics by checking out the following tutorials: