,

Resolved! | npm\ng.ps1 cannot be loaded because running scripts is disabled on this system.

If you are working on Windows 10 and using Visual Studio Code (VS Code) for your project, you might have faced an error message saying: ng : ~\npm\ng.ps1 cannot be loaded because running scripts is disabled on this system. Why do We Face this Error? When we try to run npm scripts within the VS…

By.

•

min read

If you are working on Windows 10 and using Visual Studio Code (VS Code) for your project, you might have faced an error message saying:

ng : ~\npm\ng.ps1 cannot be loaded because running scripts is disabled on this system.

Why do We Face this Error?

When we try to run npm scripts within the VS Code terminal, then this frustrating issue comes up. It indicates that the PowerShell is not allowed to execute the executable script on the system,.

This issue arises due to security measures to prevent unauthorized execution on Windows systems, where Powershell is not allowed to run any of the executable scripts by default.

Well, don’t worry we have s straightforward solution to quickly fix and overcome the obstacle and get back on track.

 

The Solution

Let’s check the quick steps to enable the PowerShell to execute scripts in VC Code terminal:

 

Step 1: Adjust Execution Policy

In this first step, we will be modifying the execution policy for PowerShell, which will enable use to execute the scripts. We will use the PowerShell command-line terminal to achieve this.

  1. Open the PowerShell terminal, you can search for “PowerShell” in your Windows search bar.
  2. Now, Right-click on the PowerShell application and choose “Run as administrator” to have the necessary privileges.
  3. In the PowerShell terminal now execute the following command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

This command will allow the scripts signed by a trusted publisher to be executed, but still prevent the execution of scripts without any digital signature.

 

Step 2: Close Instances

After we have executed the above script to enable execution of signed scripts, second important step is to ensure that all instances of Command Prompt (CMD) and Visual Studio Code are closed and restarted before to test the npm script executions.

 

Conclusion

Facing errors is frustrating but these problems give us the opportunity to learn new things and that also with many details when we try to explore more related topics.

After following the above quick steps the issue will be resolved. The ‘ng.ps1 cannot be loaded’ error is a common issue we face while working with npm scripts in Visual Studio Code on Windows 10.

Remember, that we are making changes to the system setting, so be cautious and aware of the implications. Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *