问题描述
当我尝试在VS Code中的终端中运行命令时,出现以下错误。我该如何解决?
ionic : File C:\Users\Lakshan\AppData\Roaming\npm\ionic.ps1 cannot be loaded because running scripts is disabled on this system. For more @R_698_4045@ion,see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ~~~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
解决方法
这是因为执行策略。这定义了Powershell脚本的运行方式。
在默认Windows桌面中,它是受限制的,不允许任何脚本(带符号的或无符号的)仅交互式会话。
最好使用RemoteSigned
(Windows Server上的默认设置)进行设置,只允许远程运行的已签名脚本运行,而本地未运行的已签名脚本运行,但是Unrestriced
是不安全的让所有脚本运行。
要设置以管理员身份运行Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
。
我找到了一种解决此错误的方法。如下,
首先打开powerShell 作为以管理员身份运行。
然后,在PowerShell中运行此命令
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
然后输入Y
并按Enter。