【问题标题】:why am I suddenly getting: ng : File C:\Users\d\AppData\Roaming\npm\ng.ps1 cannot be loaded为什么我突然得到:ng:无法加载文件 C:\\Users\\d\\AppData\\Roaming\\npm\\ng.ps1
【发布时间】:2023-01-04 02:57:23
【问题描述】:

多年来,我一直愉快地使用 vscode/angular/node/npm,没有任何问题。在最后一个小时左右突然没有明确更改任何内容,我收到以下错误。

之前存在的执行权限突然丢失的最可能原因是什么?

我不想提前说这个,但对于那些无法理解的人,我不是在问如何修复错误。我在问为什么我的权限被擦除导致它出现。

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\d> cd C:\source\my-WebApp
PS C:\source\my-WebApp> ng serve
ng : File C:\Users\d\AppData\Roaming\npm\ng.ps1 cannot be loaded. The file
C:\Users\d\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
PS C:\source\my-WebApp>

显然这是修复: PS C:\source\my-WebApp> Get-ExecutionPolicy -list

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       AllSigned


PS C:\source\my-WebApp> set-ExecutionPolicy RemoteSigned -Scope CurrentUse

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y
PS C:\source\my-WebApp> Get-ExecutionPolicy -list

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    RemoteSigned
 LocalMachine       AllSigned

【问题讨论】:

  • 删除 ng.ps1,它可能会起作用。
  • 我在最初的问题中包含了正确的修复方法。问题是为什么权限一开始就突然消失了。

标签: angular visual-studio-code npm


【解决方案1】:

这发生在您的系统中,power shell 还不允许执行任何可执行脚本。此错误主要在 Windows 10 中使用 VS Code IDE 时遇到,其中 Power Shell 默认情况下被选为命令行选项。

您可以通过在同一 Powershell 终端中执行以下 CMD 命令来解决此问题

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

您可以从this阅读信息。

或者,您可以删除此文件并再次运行 ng serve。 祝你好运!

【讨论】:

  • 这没有回答问题
【解决方案2】:

遇到同样的问题, 设置执行策略 -ExecutionPolicy RemoteSigned -Scope CurrentUser

为我工作,谢谢!

【讨论】:

    猜你喜欢
    • 2014-12-23
    • 2021-03-08
    • 1970-01-01
    • 2014-12-04
    • 2021-03-07
    • 2014-09-26
    • 2017-07-29
    • 2023-01-05
    • 1970-01-01
    相关资源
    最近更新 更多