为什么 powershell 没有 运行 Angular 命令?

Why powershell does not run Angular commands?

我已经开始学习 Angular 但我注意到 Windows 中的 powershell 每当我发出 angular 命令时都会给我一个错误:

ng new new-app

ng serve

这是我得到的错误:

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。我在 cmd 中尝试了这些命令并且它有效。

从目录 C:\Users\%username%\AppData\Roaming\npm\ 中删除 ng.ps1 然后尝试清除位于 C:\Users\%username%\AppData\Roaming\npm-cache\

的 npm 缓存

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

此错误是由于一项安全措施导致的,该措施不会让脚本在未经您批准的情况下在您的系统上执行。您可以通过打开具有管理权限的 powershell(在主菜单中搜索 powershell 并从上下文菜单中以管理员身份搜索 select 运行)并输入:

set-executionpolicy remotesigned

打开 windows powershell,运行 以管理员身份并将执行策略设置为不受限制,然后它将起作用。

我通过以下命令 运行 解决了我的问题

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

步骤 1

首先,您需要打开命令提示符和运行这个命令。

set-ExecutionPolicy RemoteSigned -Scope CurrentUser

步骤 2

现在您必须 运行 您系统上的第二个命令。这个命令是:

Get-ExecutionPolicy

步骤 3

要查看他们的策略,您需要在命令提示符中运行执行此命令:

Get-ExecutionPolicy -list

https://www.c-sharpcorner.com/article/how-to-fix-ps1-can-not-be-loaded-because-running-scripts-is-disabled-on-this-sys/