提供 ng 服务时出现 CLI 错误

Roh*_*an 10 angular

ng : File C:\Users\Lenovo\AppData\Roaming\npm\ng.ps1 cannot be loaded. The file C:\Users\Lenovo\AppData\Roaming\npm\ng.ps1 is not digitally signed. You cannot run 
this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at 
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ng serve
+ ~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
Run Code Online (Sandbox Code Playgroud)

在给 ng 服务时显示此错误..如何克服它?

Alo*_*hoo 9

从同一终端或命令提示符运行以下命令,然后重新运行 ng 命令以检查它是否在您的计算机上运行。

命令是=> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser


Mwi*_*iza 5

您需要使用以下命令将 CurrentUser 的 Scope 执行策略设置为 RemoteSigned:

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


小智 1

从目录 C:\Users\< 用户名 >\AppData\Roaming\npm\ 中删除 ng.ps1,然后尝试清除 C:\Users\< 用户名 >\AppData\Roaming\npm-cache\ 处的 npm 缓存

对我来说这有效,只是遇到了同样的问题。

此修复程序的作者来自帖子。