发布于 2026-01-06 7 阅读
0

如何修复错误 - nodemon.ps1 无法加载,因为此系统上已禁用脚本运行

如何修复错误 - nodemon.ps1 无法加载,因为此系统上已禁用脚本运行

Windows 系统下本地运行 nodemon 时出错的解决方案:

nodemon.ps1 cannot be loaded because running scripts is disabled on this system. For more 
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
Enter fullscreen mode Exit fullscreen mode

所以,如果您遇到此错误,只需按照以下步骤即可解决问题——

第一步:

以管理员身份运行 Windows PowerShell。

第二步:

如您所见,错误信息与执行策略有关,首先需要查看当前的执行策略。请使用 Windows PowerShell 中的以下命令获取它。

Get-ExecutionPolicy
Enter fullscreen mode Exit fullscreen mode

您会看到“受限”字样。因此,主要原因在于——在此系统上运行脚本是“受限”的。

步骤 3:

现在我们需要更改此策略以允许此操作。使用以下命令将其设置为不受限制 -

Set-ExecutionPolicy Unrestricted
Enter fullscreen mode Exit fullscreen mode

这里会显示一条提示信息。按 Y 键进行更改。

就这样。为了确保万无一失,您可以再次使用此命令检查执行策略状态。

Get-ExecutionPolicy
Enter fullscreen mode Exit fullscreen mode

你会得到输出结果“不受限制”。

问题已解决。现在您可以在您的机器上使用 nodemon 了。

文章来源:https://dev.to/targetcoder/how-to-fix-error-nodemon-ps1-cannot-be-loaded-because-running-scripts-is-disabled-on-this-system-34fe