WebStorm ng.ps1 无法加载,因为在此系统上禁用了运行脚本

问题描述 投票:0回答:2

我有一个错误:

ng:无法加载文件

....\node_modules\.bin\ng.ps1
,因为在此系统上禁用了运行脚本。有关详细信息,请参阅 about_Execution_Policies,网址为 https://go.microsoft.com/fwlink/?LinkID=135170
在行:1 字符:1

在 WebStorm 中使用 Angular,这个简单的命令对我有帮助:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

如果有人知道这个命令的作用,我将不胜感激。我想了解更多信息,问题是什么以及为什么我在互联网上找到的这个命令对我有帮助。

感谢 https://stackoverflow.com/users/7296835/stanley-mohlala 的命令。

没有 ng 命令起作用。

ng generate component xxxxx

都不是

ng g component xxxx

都不是

ng g c xxxx

我也看不到 Angular 版本,出现错误。

ng version

错误:

ng:无法加载文件

C:\www\angular004560\node_modules\.bin\ng.ps1
,因为在此系统上禁用了运行脚本。有关详细信息,请参阅 about_Execution_Policies,网址为 https://go.microsoft.com/fwlink/?LinkID=135170

angular angularjs powershell visual-studio-code webstorm
2个回答
3
投票

在 Windows PowerShell 中运行

ng
命令时会出现此错误,因为出于安全考虑,Windows 默认情况下会阻止运行未签名的 powershell 脚本,因此会出现此问题。 WebStorm 使用
powershell.exe
作为默认终端。

您可以在

设置 | 中将默认 shell 更改为 
cmd.exe工具|终端、Shell 路径...,或在 PowerShell 中运行
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
来解决该问题。

有关执行策略的信息,请参阅 https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.3。另请参阅为什么 powershell 不运行 Angular 命令?

中的答案

0
投票

转到你的npm安装路径

C:\Users{用户名}\AppData\Roaming 下午 并从位置删除 ng.ps1 文件并重新编译程序。

© www.soinside.com 2019 - 2024. All rights reserved.