Unable to execute Angular CLI commands in Visual Studio Code terminal

15,523

Solution 1

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.

Solution 2

I had the same error in Windows. what I did is I set Command Prompt as the default shell Instead of PowerShell (PowerShell is default) in the terminal window where you select a terminal instance

Solution 3

The effective solution is

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

It worked successfully.

Share:
15,523
user2636874
Author by

user2636874

Updated on June 07, 2022

Comments

  • user2636874
    user2636874 almost 2 years

    I'm unable to execute Angular CLI commands in 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?

  • user2636874
    user2636874 about 5 years
    I have tried creating the project in command prompt using ng new command like ng new test-proj. after that from visual studio code I opened the above folder and next in terminal, I ran the command npm install, it executed well. after that I ran the command ng --version, then instead of executing the ng command, it is opening the ng file.
  • Damika
    Damika over 2 years
    Please do mention what is the reason to do such a change
  • nicolascolman
    nicolascolman about 2 years
    This is the easiest and most accurate answer