Angular - 无法加载 ng.ps1,因为该系统上禁用了运行脚本

use*_*561 37 angular

在我的 Angular-12 应用程序中,我尝试使用以下命令生成服务:

ng gs 身份验证/服务/登录

但我得到了这个错误:

ng : File C:\Users\akweey\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 g s auth/services/login
+ ~~
+ CategoryInfo          : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Run Code Online (Sandbox Code Playgroud)

当我检查路径:C:\Users\akweey\AppData\Roaming\npm\ng.ps1时,

我只找到了 ng 但没有找到 ng.ps1

我该如何解决这个问题?

谢谢

Dra*_*iya 127

出现此问题的原因是未定义执行策略。

在 Powershell 中尝试以下命令:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Run Code Online (Sandbox Code Playgroud)


小智 32

只要删除这个文件就可以了。C:\Users\用户名\AppData\Roaming\npm\ng.ps1

  • 这是这里最好的答案。其他解决方案让用户在其系统上创建安全漏洞。 (3认同)

Suj*_*ghe 5

在 powershell 上执行此操作,

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Run Code Online (Sandbox Code Playgroud)

接下来,“您想更改执行策略吗?” 对所有人说“是”

A
Run Code Online (Sandbox Code Playgroud)