16

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?

2
  • Have you installed @angular/cli ? Commented Feb 22, 2019 at 4:49
  • Yes, I have installed angular cli globally, npm install -g @angular/cli@latest Commented Feb 22, 2019 at 5:17

11 Answers 11

21

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.

Sign up to request clarification or add additional context in comments.

Comments

10

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.

Comments

4

The effective solution is

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

It worked successfully.

Comments

4

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

1 Comment

This is the easiest and most accurate answer
1

Type npm start instead of ng serve.

1 Comment

Please do mention what is the reason to do such a change
1

my case working fine this command please open power shell

set-executionpolicy remotesigned -Scope CurrentUse

Comments

0

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

1 Comment

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.
0

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.

Comments

0

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

Comments

0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.