跳到主内容

window环境下,Powershell运行vue命令报错

· 1分钟阅读

问题

在 window 的 cmd 下全局安装 npm install -g vue-cli ,然后执行 vue init 结果正常,但是在 powershell 下执行 vue init 则报以下错误:

vue: 无法加载文件 AppData\Roaming\npm\vue.ps1,因为此系统上禁止运行脚本。有关详情信息,请参阅 https://go.microsoft.com/fwlink/?linkid=135170 中的 about_execution_policies。

vue create material_management

+ CategoryInfo : SecurityError: (:) [],PSSecurityException

+ FullyQualifiedErrorId : UnauthorizedAccess

原因

主要是因为 Powershell 没有进行授权,需要把 ExecutionPolicy 变量改为 RemoteSigned。不止在 powershell 执行 vue 命令会出现问题,执行 create-react-app 也会有问题。

解决

解决方法也非常简单,只需要用管理员权限打开 powershell, 然后执行下面命令即可,最后输入 Y

set-ExecutionPolicy RemoteSigned

image.png