[Solved] ‘ng.ps1 Cannot Be Loaded’ Error in Angular for ng build

A simple guide for solving PowerShell script-blocking issues, so that Angular CLI runs without any errors.6 min


If you are working on Angular on Windows, you might run into an issue that says, “ng.ps1 cannot be loaded because running scripts is disabled” error. It usually appears when you run ng serve, ng build, or any Angular CLI command in PowerShell or cmd (Command Prompt).

You know, this problem happens because Windows blocks certain scripts by default. Angular CLI installs a PowerShell Script called ng.ps1 and this time, PowerShell refuses to run it unless you change the execution settings for security purposes.

Understand why this error happens!

Angular installs its CLI tools inside this folder:

C:Users<YourUser>AppDataRoamingnpm

When you run any ng command, your PowerShell tries to run the file ng.ps1. If your system’s execution policy is set to Restricted, PowerShell blocks the script and throws the given error.

Windows does this to prevent untrusted scripts from running automatically, but also note that it also blocks safe developer scripts like Angular CLI.

Here's some good news: the fix is simple. Try out the best-working solutions, which are safest and most commonly used.

Solution 1: Allow scripts only for your user (recommended)

This is the best way and a good practice too, because it updates the execution policy for your account only. It doesn’t affect system-wide security.

1. Open PowerShell as Administrator,

2. Run this command,

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

3. Close and reopen VS Code (or your respective IDE)

4. Run below command:

ng serve

By performing these steps this allows locally created scripts (like Angular CLI) to run without touching global system settings. It works for most developers; this fix is enough.

Solution 2: Allow script execution only for the current session

If you are planning not to change any policy permanently for your system or your account, you can bypass it temporarily using this method. This is safe because it resets automatically after you close the terminal (or PowerShell or CMD).

Run this command in your PowerShell terminal:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

You can now run Angular commands normally. When you close the window, the policy returns to default behaviour.

Solution 3: Switch to Command Prompt instead of PowerShell

If you prefer not to change any execution policy at all, or you have restrictions in your organisation, then this solution will work for you. Simply switch your terminal.

In your VS Code:

  1. Press Ctrl + Shift + P
  2. Search Terminal: Select Default Profile
  3. Choose Command Prompt
  4. Open a new terminal and run:
ng serve --open

In this fix, the CMD doesn’t enforce PowerShell’s restrictions, so Angular CLI works without any errors.

Solution 4: Reinstall Angular CLI (if ng.ps1 is corrupted)

Sometimes the ng.ps1 file gets corrupted or deleted by your organisation’s security or strict policy. If the above fixes don’t help, reinstalling the Angular CLI globally always works.

Run these commands:

npm uninstall -g @angular/cli
npm install -g @angular/cli

Then try again:

ng serve

A fresh install usually fixes any script-related issues.

Solution 5: Check if your Node and NPM path is correctly set

If your system can’t find the ng.ps1 file or the PATH variable is misconfigured, you can reset it by reinstalling Node.js or manually adding this path:

C:Users<YourUser>AppDataRoamingnpm

Once the PATH is correct, PowerShell will be able to find the Angular CLI script.

Wrapping Up…

Once the issue is fixed, you’ll be able to run Angular CLI commands like ng serve or ng build without interruptions. Tell me, which solution worked for you? — If you find a new way, please comment it below so other developers can also save some time! Time is precious, you know!


Discover more from 9Mood

Subscribe to get the latest posts sent to your email.


Like it? Share with your friends!

What's Your Reaction?

Lol Lol
0
Lol
WTF WTF
0
WTF
Cute Cute
0
Cute
Love Love
0
Love
Vomit Vomit
0
Vomit
Cry Cry
0
Cry
Wow Wow
0
Wow
Fail Fail
0
Fail
Angry Angry
0
Angry
Rakshit Shah

Intermediate

Hey Moodies, Kem chho ? - Majama? (Yeah, You guessed Right! I am from Gujarat, India) 25, Computer Engineer, Foodie, Gamer, Coder and may be a Traveller . > If I can’t, who else will? < You can reach out me by “Rakshitshah94” on 9MOodQuoraMediumGithubInstagramsnapchattwitter, Even you can also google it to see me. I am everywhere, But I am not God. Feel free to text me.

0 Comments

Leave a Reply

Choose A Format
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Ranked List
Upvote or downvote to decide the best list item
Open List
Submit your own item and vote up for the best submission
Countdown
The Classic Internet Countdowns
Meme
Upload your own images to make custom memes
Poll
Voting to make decisions or determine opinions
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Personality quiz
Series of questions that intends to reveal something about the personality
is avocado good for breakfast? Sustainability Tips for Living Green Daily Photos Taken At Right Moment