VSC PowerShell。npm更新后,无法加载软件包.ps1,因为此系统上的运行脚本已禁用

Apo*_*ing 4 powershell npm firebase vue.js visual-studio-code

我在VSC中设计网站,而PowerShell是我的默认终端。

在较早地将网站更新和部署到firebase之后,系统提示我更新firebase工具-我使用npm做了。在出现以下错误之后,我无法立即运行/访问任何firebase脚本后:

firebase : File C:\Users\mada7\AppData\Roaming\npm\firebase.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. At line:1 char:1

firebase + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess

我花了几个小时四处搜寻,却找不到可靠的答案。许多线程已经使用了好几年了,我觉得很奇怪,在过去的一年中直到今天我都没有遇到过这个问题。如果将默认终端设置为cmd,我仍然可以访问firebase脚本。

假设问题与我一直在使用的firebase-tools有关,但是现在更新了vue.js并在尝试在Powershell中运行任何vue命令时再次出现错误:

vue : File C:\Users\mada7\AppData\Roaming\npm\vue.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. At line:1 char:1

vue + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess

VSCode Version: Version: 1.37.1 (user setup) Commit: f06011a Date: 2019-08-15T16:17:55.855Z Electron: 4.2.7 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8: 6.9.427.31-electron.0 OS: Windows_NT x64 10.0.18362 OS Version: Windows 10 Home Version - 1903 OS build - 18362.295

我一直在阅读,并看到许多关于脚本权限的线程,但是我没有进行任何更改-实际上,PowerShell脚本在更新软件包之前一直有效。在此期间,未触及其他设置。我不想不必要地更改PowerShell设置。

小智 133

直接删除firebase.ps1文件:

文件 C:\Users\<your account>\AppData\Roaming\npm\firebase.ps1

  • 也有效,在我的例子中是文件yarn.ps1 (6认同)
  • 对我也有帮助...就我而言,它是 vue.ps1,只需将其删除,一切运行良好... (4认同)
  • 这是一个很好的解决方案。谢谢! (3认同)
  • 我在 \AppData\Roaming\npm 文件夹中没有 firebase.ps1 (3认同)

MD *_*YON 40

  1. 搜索 PowerShell
  2. 右键单击并以管理员身份运行
  3. 运行这个简单的命令 Set-ExecutionPolicy RemoteSigned
  4. A输入


kmg*_*mgt 19

对于那些使用 VS Code 并收到about_Execution_Policies错误的人。就我而言,使用命令ncu -unpm-check-updates)。

用CMD试试:

在此输入图像描述

只需再次执行CMD中的命令即可。

如果此方法有效,安全设置可以保持原样。


小智 16

一点说明:当您以管理员身份运行 PowerShell 时,在大多数情况下,您不需要记下路径。只需输入:

Set-ExecutionPolicy RemoteSigned
Run Code Online (Sandbox Code Playgroud)

然后按“A”,然后按“Enter”


小智 12

此外,值得一提的是,您需要以管理员身份打开 PowerShell,然后像这样更改策略。

PS C:\> Set-ExecutionPolicy RemoteSigned

参考 - 使用 Set-ExecutionPolicy Cmdlet


Sah*_*oru 12

  1. 搜索powershell

  2. 右键单击以管理身份运行

  3. 运行这个简单的命令Set-ExecutionPolicy RemoteSigned

  4. A输入

  5. 转到代码并运行yarn add <YOUR_MODULE>

  6. 按 Enter 键。

现在恭喜它完成了。


小智 6

这可能是由于当前用户具有未定义的 ExecutionPolicy。

你可以试试下面的

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted


Tus*_*rtz 5

这是一个Powershell安全策略,要对其进行修复,请运行以下命令

PS C:\> Set-ExecutionPolicy RemoteSigned 
Run Code Online (Sandbox Code Playgroud)

策略越严格,系统就越安全。

你可以改变下RemoteSigned到其他选项,如:RestrictedAllSignedRemoteSignedUnrestricted

来源:https : //tecadmin.net/powershell-running-scripts-is-disabled-system/


Roh*_*aki 5

我在 powershell 中也遇到了这个问题,我使用了以下命令:然后我再次安装了服务包。

 Set-ExecutionPolicy -Scope CurrentUser
Run Code Online (Sandbox Code Playgroud)

然后我选择Unrestricted并发出serve命令,它起作用了。


小智 5

我对 npm 没有任何问题,但在 windows 上使用 yarn 也有同样的问题。就我而言,我删除了yarn.ps1 并且对我来说效果很好:

文件路径:

C:\Users\<your account>\AppData\Roaming\npm\yarn.ps1
Run Code Online (Sandbox Code Playgroud)