为什么我突然觉得ng:无法加载文件C:\用户\d\应用程序数据\漫游\npm\ng.ps1

x4shl7ld  于 2023-01-05  发布在  其他
关注(0)|答案(1)|浏览(261)

我已经愉快地使用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\我的Web应用〉获取执行策略列表

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
wribegjk

wribegjk1#

这是因为您的系统,电源 shell 尚未被允许执行任何可执行脚本。此错误主要发生在Windows 10中,当使用VS代码IDE时,电源 shell 被选为默认的命令行选项。
您可以通过在同一Powershell终端中执行以下CMD命令来解决此问题

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

您可以从this读取信息。
否则,您可以删除此文件并再次运行ng serve。祝您好运!

相关问题