user2636874
user2636874

Reputation: 899

Unable to execute Angular CLI commands in Visual Studio Code terminal

I'm unable to execute Angular CLI commands from the Visual Studio Code terminal.

When I type ng --version in the terminal, it is opening the ng file instead of executing the command.

Any idea of how to resolve the above issue?

Upvotes: 16

Views: 33395

Answers (11)

Abdullah
Abdullah

Reputation: 1

To fix this error you have to open your Windows Powershell as administrator.

Then write

Command: set-executionpolicy remotesigned

and after that select

"A"

to Yes to all.

Hit enter and then try to run your application in VS Code's Powershell with ng serve command.

Upvotes: 0

Alvinne James Barron
Alvinne James Barron

Reputation: 101

I had the same error on Windows.

What I did is to set Command Prompt as the default shell instead of PowerShell (PowerShell is the default) in the terminal window where you select a terminal instance.

Upvotes: 10

JIBINA
JIBINA

Reputation: 21

ng serve comand opens an editor instead of loading local URL Issue

Solution: This is the terminal editor on the 'ng' alias. Uninstall it with:

Command: sudo apt purge ng-common ng-latin

Then install Angular CLI (assuming you have npm installed) with Command: sudo npm install -g @angular/cli

After that You can use all ng commands

Upvotes: 0

Aamir Hussain
Aamir Hussain

Reputation: 187

my case working fine this command please open power shell

set-executionpolicy remotesigned -Scope CurrentUse

Upvotes: 1

Damika
Damika

Reputation: 812

I too faced to this problem. And

  • I solved the problem when starting the angular server by using npm start instead of ng serve I think the reason for this is, angular's dev server is webpack. And on default webpack works on development mode with npm start
  • But above way didn't work for me when executing other angular-cli commands on vs-code terminal.
  • So I went to the documentation of vs-code (mentioned below on recourses section)
  • Initially they ask to check the execution policy by executing Get-ExecutionPolicy on power shell of vs-code -> I got Restricted
  • Next Get-ExecutionPolicy -List to get all of the execution policies with their scorps. And I got the follwing result :/

MachinePolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Undefined

  • Then I rechecked the error which was displayed at the beginning, in vs-code power shell

    'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. To change the execution policy
    execution policy for the current user, run "Set-ExecutionPolicy -Scope CurrentUser".

  • In there too it's mentioned the err is about the current-user

  • So I execute Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

  • And it worked for me. It's pleasure if this would work to you too thanks.

Recourses: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2

Upvotes: 0

Elis Padsala
Elis Padsala

Reputation: 11

Type npm start instead of ng serve.

Upvotes: 1

SandstormNick
SandstormNick

Reputation: 2011

When you open a new terminal in VS Code, in the top right corner you are given a couple option icons: enter image description here

Click on the dropdown icon and you get a couple options to choose from:

  • Powershell (default)
  • Command Prompt
  • Git Bash
  • JavaScript Debug Terminal

There is also a "Configure Terminal Settings" which allows you to change the default terminal window

Upvotes: 3

kripa
kripa

Reputation: 41

The effective solution is

  1. opening the microsoft studio code by run as administrator
  2. set-executionpolicy remotesigned
  3. ng serve

It worked successfully.

Upvotes: 4

dalailmao
dalailmao

Reputation: 9

Not sure with your question but try using Angular-CLI commands runner inside VS Code extension in your VS Code. Works very smooth for me.

Upvotes: 0

dev
dev

Reputation: 211

I got the following error message while executing ng serve from VSCode:

File C:\Users\\AppData\Roaming\npm\ng.ps1 cannot be loaded because running scripts is disabled on this system...

Solution:

I was able to solve the issue by running the following command in PowerShell:

set-executionpolicy remotesigned

Make sure to run PowerShell with admin privileges. More on this solution can be read here.

Upvotes: 21

Saurabh Gupta
Saurabh Gupta

Reputation: 345

Try doing npm install inside your project directory and then try for ng --version.

Upvotes: 0

Related Questions