Ng.ps1 cannot be loaded because running scripts is disabled on this system angular

Dung Do Tien Nov 16 2020 969

My project was written by Angular version 8, daily I still run normal but today after running the command ng serve -o I got an error as below:

ng : File C:\\Users\\QuizDev\\AppData\\Roaming\\npm\\ng.ps1 cannot be loaded because  running scripts is disabled on this system. For more information, see  about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1 + ng serve + ~~     + CategoryInfo          : SecurityError: (:) [], PSSecurityException     + FullyQualifiedErrorId : UnauthorizedAccess

Please suggest to me if you know any reason.

  • Angular

Have 2 answer(s) found.

  • S

    1

    Sandeep Kumar Nov 16 2020

    You can try to do as below:

    Remove ng.ps1 file from the directory C:/Users/QuizDev/AppData/Roaming/npm/ng.ps1  then try clearing the npm cache at C:/Users/QuizDev/AppData/Roaming//npm-cache

    I hope it works for you.

  • M

    -1

    Marry Christ Nov 16 2020

    I also get the same error, I resolved this issue by running the command below in cmd of root project Angular:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

    I hope it's work for you.

If this answer is useful for you, please BUY ME A COFFEE!!! I need your help to maintain blog.

  1. Error: Cannot redeclare block-scoped variable in Typescript
  2. ReferenceError: $ is not defined in Angular version 11
  3. 'rxjs/Observable' has no exported member 'Observable' in Angular
  4. Error: Could not find any Python installation to use in Angular 11
  5. You seem to not be depending on "@angular/core" and/or "rxjs" in Angular
  6. Error: PostCSS plugin postcss-discard-comments requires PostCSS 8 in Angular 7
  7. Error TS1086: An accessor cannot be declared in an ambient context in Angular
  8. ENOENT: no such file or directory, lstat coreui-icons.css in Angular
  9. Module not found: Error: Can't resolve '@angular/localize/init' in Angular
  10. Error: Cannot find module '@angular-devkit/core' in Angular 9
  11. TypeError: Cannot read property 'props' of undefined in ReactJS
  12. Can't bind to 'ngModel' since it isn't a known property of 'input' in Angular
  13. Error: Node Sass does not yet support your current environment in Angular
  14. Angular 9 throw error "ng: command not found" in MacOS
  15. Angular: No value accessor for form control with unspecified name attribute

Leave An Answer

* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Start Test

Javascript - Functions

45 Jun 12 2020

Start Test

Asp.Net Core - Exam test 01

269 Mar 09 2021

Start Test

Asp.Net Core - Exam test 02

115 Jul 25 2021

Start Test

C# - Level Beginner

47 Jul 25 2021

This error I encountered when I tried to use integrated terminal of visual studio code for executing Angular CLI commands for the first time.

Exception Details:

\AppData\Roaming\npm\ng.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1~~

CategoryInfo : SecurityError: (:) [], PSSecurityException

FullyQualifiedErrorId : UnauthorizedAccess

Problem

The issue appear to be security related exception. Also we can observe Unauthorized Access as error Id in exception details.

Ng.ps1 cannot be loaded because running scripts is disabled on this system angular

So the issue is Visual Studio Code could not load ng.ps1 file due to security reasons. Also exception is suggesting to refer Microsoft website article as Visual Studio Code is Microsoft product.

Solution

To solve the issue I could navigate to the file and deleted the ng.ps1 file as shown in below screen shot. After deleting that file I could go ahead with Angular CLI command execution in Visual Studio Code integrated terminal.

Ng.ps1 cannot be loaded because running scripts is disabled on this system angular

Video Tutorial

This video shows how to solve the above issue with above solution

Video Tutorial

Summary

These are some small errors which we can solve if we try to analyze the exception and apply some basic actions.

Software professional with 7+ years of experience in all phases of software development with robust problem-solving skills and proven experience in creating and designing software in a test-driven environment.

Why is running scripts disabled on this system?

While running PowerShell script, if you get running scripts is disabled on this system, it is because the PowerShell execution policy is set up by default as Restricted and doesn't allow to run script. PowerShell has built-in security features implemented.

How do I enable PowerShell scripts?

Open Run Command/Console ( Win + R ).
Type: gpedit. msc (Group Policy Editor).
Browse to Local Computer Policy -> Computer Configuration -> Administrative Templates -> Windows Components -> Windows Powershell..
Enable "Turn on Script Execution".
Set the policy as needed. I set mine to "Allow all scripts"..

How do I enable scripts?

In the Security Settings – Internet Zone dialog box, click Enable for Active Scripting in the Scripting section. When the "Warning!" window opens and asks, "Are you sure you want to change the settings for this zone?" select Yes. Click OK at the bottom of the Internet Options window to close the dialog.