windows http-server 因为在此系统上禁止运行脚本

我想在windows中运行 http-server 安装方法:

npm install http-server -g

这个在linuxt和macOS中使用都是非常的方便的,但是在windows中运行缺报错了。

报错信息

http-server
http-server : 无法加载文件 C:\Users\itkey\AppData\Roaming\npm\http-server.ps1,因为在此系统上禁止运行脚本。有关详细信息
,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ http-server
+ ~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

原因分析

查了查之后发现是在计算机上启动 Windows PowerShell 时,执行策略很可能是 Restricted(默认设置)。

Restricted 执行策略不允许任何脚本运行。

AllSigned 和 RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本。

本主题说明如何运行所选未签名脚本(即使在执行策略为 RemoteSigned 的情况下),还说明如何对 脚本进行签名以便您自己使用。

有关 Windows PowerShell 执行策略的详细信息,请参阅 about_Execution_Policy。

想了解 计算机上的现用执行策略,打开PowerShell 然后输入

get-executionpolicy

在这里插入图片描述

解决办法

以管理员身份打开PowerShell 输入

set-executionpolicy remotesigned

在这里插入图片描述
这样就可以正常运行了。

参考

《about_Execution_Policies》
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2
《PowerShell:因为在此系统上禁止运行脚本,解决方法》
https://www.jianshu.com/p/4eaad2163567

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值