[javascript] Why powershell does not run Angular commands?

I have started to learn Angular but I note that powershell in Windows gives me an error whenever I make an angular command like:

ng new new-app

or

ng serve

this is the error what I got:

ng : File C:\Users\< username >\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

P.S. I try these commands in cmd and it works.

This question is related to javascript angular powershell angular-cli

The answer is


Remove ng.ps1 from the directory C:\Users\%username%\AppData\Roaming\npm\ then try clearing the npm cache at C:\Users\%username%\AppData\Roaming\npm-cache\


I solved my problem by running below command

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser


script1.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170

This error happens due to a security measure which won't let scripts be executed on your system without you having approved of it. You can do so by opening up a powershell with administrative rights (search for powershell in the main menu and select Run as administrator from the context menu) and entering:

set-executionpolicy remotesigned

open windows powershell, run as administrater and SetExecution policy as Unrestricted then it will work.


Questions with javascript tag:

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax Drag and drop menuitems Is it possible to execute multiple _addItem calls asynchronously using Google Analytics? DevTools failed to load SourceMap: Could not load content for chrome-extension TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined raised when starting react app What does 'x packages are looking for funding' mean when running `npm install`? SyntaxError: Cannot use import statement outside a module SameSite warning Chrome 77 "Uncaught SyntaxError: Cannot use import statement outside a module" when importing ECMAScript 6 Why powershell does not run Angular commands? Typescript: No index signature with a parameter of type 'string' was found on type '{ "A": string; } Uncaught Invariant Violation: Too many re-renders. React limits the number of renders to prevent an infinite loop Push method in React Hooks (useState)? JS file gets a net::ERR_ABORTED 404 (Not Found) React Hooks useState() with Object useState set method not reflecting change immediately Can't perform a React state update on an unmounted component UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block Can I set state inside a useEffect hook internal/modules/cjs/loader.js:582 throw err How to post query parameters with Axios? How to use componentWillMount() in React Hooks? React Hook Warnings for async function in useEffect: useEffect function must return a cleanup function or nothing FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory in ionic 3 How can I force component to re-render with hooks in React? What is useState() in React? How to call loading function with React useEffect only once Objects are not valid as a React child. If you meant to render a collection of children, use an array instead How to reload current page? Center content vertically on Vuetify Getting all documents from one collection in Firestore ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment How can I add raw data body to an axios request? Sort Array of object by object field in Angular 6 Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) Axios Delete request with body and headers? Enable CORS in fetch api Vue.js get selected option on @change Bootstrap 4 multiselect dropdown Cross-Origin Read Blocking (CORB) Angular 6: How to set response type as text while making http call

Questions with angular tag:

error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class error TS1086: An accessor cannot be declared in an ambient context in Angular 9 TS1086: An accessor cannot be declared in ambient context @angular/material/index.d.ts' is not a module Why powershell does not run Angular commands? error: This is probably not a problem with npm. There is likely additional logging output above Angular @ViewChild() error: Expected 2 arguments, but got 1 Schema validation failed with the following errors: Data path ".builders['app-shell']" should have required property 'class' Access blocked by CORS policy: Response to preflight request doesn't pass access control check origin 'http://localhost:4200' has been blocked by CORS policy in Angular7 How to set value to form control in Reactive Forms in Angular Typescript: Type X is missing the following properties from type Y length, pop, push, concat, and 26 more. [2740] WARNING in budgets, maximum exceeded for initial ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead Angular CLI Error: The serve command requires to be run in an Angular project, but a project definition could not be found How to set width of mat-table column in angular? How to reload current page? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment How to convert string to boolean in typescript Angular 4 Angular: How to download a file from HttpClient? Confirm password validation in Angular 6 Angular 6: saving data to local storage How to use mouseover and mouseout in Angular 6 get current date with 'yyyy-MM-dd' format in Angular 4 Sort Array of object by object field in Angular 6 Setting values of input fields with Angular 6 Select default option value from typescript angular 6 Angular 6: How to set response type as text while making http call Set default option in mat-select How to do a timer in Angular 5 Can not find module “@angular-devkit/build-angular” Could not find module "@angular-devkit/build-angular" How to remove package using Angular CLI? How to add bootstrap in angular 6 project? Can't bind to 'dataSource' since it isn't a known property of 'table' Angular 6 Material mat-select change method removed How to set environment via `ng serve` in Angular 6 Angular 5 Button Submit On Enter Key Press ERROR Error: StaticInjectorError(AppModule)[UserformService -> HttpClient]: Set focus on <input> element How to import a new font into a project - Angular 5 Angular - "has no exported member 'Observable'" Uncaught (in promise): Error: StaticInjectorError(AppModule)[options] Property '...' has no initializer and is not definitely assigned in the constructor Angular 5 ngHide ngShow [hidden] not working What could cause an error related to npm not being able to find a file? No contents in my node_modules subfolder. Why is that? Angular - How to apply [ngStyle] conditions How to remove whitespace from a string in typescript? Angular 5 - Copy to clipboard

Questions with powershell tag:

Why powershell does not run Angular commands? How do I install the Nuget provider for PowerShell on a unconnected machine so I can install a nuget package from the PS command line? How to print environment variables to the console in PowerShell? Check if a string is not NULL or EMPTY The term 'ng' is not recognized as the name of a cmdlet VSCode Change Default Terminal 'Connect-MsolService' is not recognized as the name of a cmdlet Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet Change directory in PowerShell ps1 cannot be loaded because running scripts is disabled on this system How do I force Robocopy to overwrite files? How to use the curl command in PowerShell? Changing PowerShell's default output encoding to UTF-8 Upload file to SFTP using PowerShell Convert a string to datetime in PowerShell Catching FULL exception message The response content cannot be parsed because the Internet Explorer engine is not available, or Extract the filename from a path Making a PowerShell POST request if a body param starts with '@' If strings starts with in PowerShell Powershell: A positional parameter cannot be found that accepts argument "xxx" Powershell script to check if service is started, if not then start it How to convert string to integer in PowerShell Read file line by line in PowerShell How open PowerShell as administrator from the run window A better way to check if a path exists or not in PowerShell Check if a file exists or not in Windows PowerShell? Ternary operator in PowerShell Splitting a string into separate variables Simple InputBox function How can I find the product GUID of an installed MSI setup? Running PowerShell as another user, and launching a script How do I check if a PowerShell module is installed? How do I assign a null value to a variable in PowerShell? How to Correctly Check if a Process is running and Stop it Convert a secure string to plain text Use Invoke-WebRequest with a username and password for basic authentication on the GitHub API How to unzip a file in Powershell? How to switch to another domain and get-aduser You cannot call a method on a null-valued expression Out-File -append in Powershell does not produce a new line and breaks string into characters User Get-ADUser to list all properties and export to .csv How can I verify if an AD account is locked? How can you test if an object has a specific property? Powershell: count members of a AD group Powershell folder size of folders without listing Subdirectories How to overwrite files with Copy-Item in PowerShell Using "-Filter" with a variable How do I use Join-Path to combine more than two strings into a file path?

Questions with angular-cli tag:

Why powershell does not run Angular commands? ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead Angular CLI Error: The serve command requires to be run in an Angular project, but a project definition could not be found Could not find module "@angular-devkit/build-angular" How to remove package using Angular CLI? How to set environment via `ng serve` in Angular 6 Error: Local workspace file ('angular.json') could not be found How do I deal with installing peer dependencies in Angular CLI? How to iterate using ngFor loop Map containing key as string and values as map iteration how to format date in Component of angular 5 How to generate components in a specific folder with Angular CLI? How to rename a component in Angular CLI? How to check the Angular version? How to generate .angular-cli.json file in Angular Cli? The term 'ng' is not recognized as the name of a cmdlet Angular CLI - Please add a @NgModule annotation when using latest 'ng' is not recognized as an internal or external command, operable program or batch file Global Angular CLI version greater than local version How to create a new component in Angular 4 using CLI How to upgrade Angular CLI to the latest version Installing a specific version of angular with angular cli Cannot find name 'require' after upgrading to Angular4 How to load image (and other assets) in Angular an project? Angular cli generate a service and include the provider in one step You seem to not be depending on "@angular/core". This is an error How to remove components created with Angular-CLI How to decrease prod bundle size? How to upgrade Angular CLI project? What is the best way to delete a component with CLI Checking version of angular-cli that's installed? How to change Angular CLI favicon tslint / codelyzer / ng lint error: "for (... in ...) statements must be filtered with an if statement" Angular-cli from css to scss How to change angular port from 4200 to any other How to execute only one test spec with angular-cli Create component to specific module with Angular-CLI When to use 'npm start' and when to use 'ng serve'? How to uninstall/upgrade Angular CLI? angular-cli where is webpack.config.js file - new angular6 does not support ng eject You have to be inside an angular-cli project in order to use the build command after reinstall of angular-cli how to end ng serve or firebase serve How to add font-awesome to Angular 2 + CLI project ng is not recognized as an internal or external command Set default host and port for ng serve in config file How to add bootstrap to an angular-cli project How to bundle an Angular app for production how to change the dist-folder path in angular-cli after 'ng build' ng: command not found while creating new project using angular-cli angular-cli server - how to proxy API requests to another server? angular-cli server - how to specify default port