【问题标题】:VSC PowerShell. After npm updating packages .ps1 cannot be loaded because running scripts is disabled on this systemVSC PowerShell。在 npm 更新包后,无法加载 .ps1,因为在此系统上禁用了运行脚本
【发布时间】:2019-12-31 14:09:24
【问题描述】:

我在 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 脚本。

假设问题与我一直在工作但现在已更新 vue.js 并在尝试在 powershell 中运行任何 vue 命令时再次出现错误的 firebase-tools 相关:

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 设置。

【问题讨论】:

  • 这个问题开始于 2019 年 11 月左右使用 npm 的几个应用程序。那时 npm 开始使用 powershell 脚本。请参阅this npm 拉取请求和此后续 npm 问题 470。github.com/npm/cli/issues/470

标签: firebase powershell vue.js npm visual-studio-code


【解决方案1】:

只需删除firebase.ps1文件:

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

【讨论】:

  • 我在 \AppData\Roaming\npm 文件夹中没有 firebase.ps1
  • 对我也有帮助...在我的情况下它是 vue.ps1,刚刚删除它并且一切正常...
  • 在我的例子中,它是 touch.ps1,将它从那里移动,它现在可以工作了!如果我所做的是对还是错,我不知道是什么意思
  • 我遇到了同样的问题,http-server.ps1 删除文件解决了问题
  • 也有效,在我的情况下它是文件 yarn.ps1
【解决方案2】:

这是一个 powershell 安全策略,要修复它,以管理员身份运行 Powershell 并运行以下命令

PS C:\> Set-ExecutionPolicy RemoteSigned 

如果您不想以管理员身份运行命令,而只想为当前用户运行,则可以添加如下所示的范围

PS C:\> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

政策越严格,您的系统就越安全。

您可以将 RemoteSigned 更改为其他选项,例如:RestrictedAllSignedRemoteSignedUnrestricted

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

您也可以使用文本编辑器修改C:\Program Files\PowerShell\7\powershell.config.json,然后添加或修改以下部分。

{
   ....

   "Microsoft.PowerShell:ExecutionPolicy":  "RemoteSigned"
}

【讨论】:

  • 感谢您的回复。实际上,我已经遇到过该网站,并且由于错误发生而不愿更改任何内容,而无需我更改任何内容或安装/重新启动计算机。我现在已经在 PowerShell 中更改了我的设置,它像以前一样运行脚本,有什么我应该关心的更改吗?我最初在 gitHub 上发布了这个问题,有几个人有同样的问题。 github.com/firebase/firebase-tools/issues/1627
  • @Aponting 只要您的电脑上没有可能将数据路由到外部服务器的恶意软件,应该没问题。最好也安装一个防病毒软件,但我认为如果你不使用不可靠的网站或软件也不必担心
  • 在 windows powershell 中执行 Set-ExecutionPolicy RemoteSigned 现在可以工作了。谢谢。
【解决方案3】:
  1. 搜索powershell
  2. 右键单击并以管理员身份运行
  3. 运行这个简单的命令Set-ExecutionPolicy RemoteSigned
  4. AEnter

【讨论】:

    【解决方案4】:

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

    Set-ExecutionPolicy RemoteSigned
    

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

    【讨论】:

      【解决方案5】:

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

      PS C:\> Set-ExecutionPolicy RemoteSigned

      Reference - Using the Set-ExecutionPolicy Cmdlet

      【讨论】:

        【解决方案6】:

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

        你可以试试下面的

        Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

        【讨论】:

          【解决方案7】:

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

          文件路径:

          C:\Users\<your account>\AppData\Roaming\npm\yarn.ps1
          

          【讨论】:

            【解决方案8】:

            我在 powershell 中也遇到了这个问题,我使用了以下内容: 然后我再次安装了 serve 包。

             Set-ExecutionPolicy -Scope CurrentUser
            

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

            【讨论】:

              【解决方案9】:

              您可以简单地使用cmd,而不是使用PowerShell 并更改其安全设置。它不会报错,你的所有命令都会顺利运行。

              请记住,PowerShell 更强大且更敏感。因此,Microsoft 默认禁用运行 .ps1 文件,因为它可能会导致安全问题并损害您的电脑。所以,这就是为什么您应该尝试使用 cmd 而不是更改 PowerShell 安全性。

              【讨论】:

                【解决方案10】:

                无法加载文件C:\Users\xxxx\AppData\Roaming\npm\vue.ps1,因为在此系统上禁用了运行脚本。

                我在使用 vue 时遇到了同样的错误消息。 成功运行以下命令后

                npm install -g @vue/cli 
                

                当我运行vuevue --version 之类的命令时,我收到了该错误消息。

                这就是我修复它的方法: 我按下按钮windows + E,单击view,检查hidden items。 然后,我去了C:\Users\xxxx\AppData\Roaming\npm文件夹并删除了'windows powershell script'类型的vue文件。 之后,我成功运行了命令vuevue --version。 希望这会有所帮助。

                【讨论】:

                • 作为更新 - 我在更新 firebase 和 vue 后经常收到错误,因此每次都删除相关的 .ps 文件而不会出现问题,因为我不愿意更改脚本设置
                【解决方案11】:

                删除firebase.ps1位于:

                C:\Users\<your account>\AppData\Roaming\npm\
                

                如果您没有firebase.ps1,请删除vue.ps1

                【讨论】:

                  【解决方案12】:

                  我不知道它是否对 Firebase 有帮助,但我在使用 *&gt;npm install -g @vue/cli* 安装 Vue 时遇到了类似的问题。

                  长话短说:
                  我从 C:\Users\XXX\AppData\Roaming\npm\ 中删除了 vue.ps1 并从 VsCode *&gt;npm install @vue/cli* 内的 powershell 终端本地安装(没有 -g)。
                  之后我就可以毫无问题地使用 Vue 命令了。

                  【讨论】:

                    【解决方案13】:

                    打开 Powershell 并执行以下命令:

                    set-ExecutionPolicy RemoteSigned -Scope CurrentUser
                    

                    【讨论】:

                      【解决方案14】:

                      从您的 VS 代码中打开 Powershell,然后在其上执行以下命令:

                      set-ExecutionPolicy RemoteSigned -Scope CurrentUser
                      

                      这对我有用。它会要求您进行 CLI 身份验证。

                      【讨论】:

                        【解决方案15】:

                        对于那些使用 VS Code 并收到 about_Execution_Policies 错误的人。在我的情况下,使用命令 ncu -u (npm-check-updates)。

                        用 CMD 试试:

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

                        如果可行,安全设置可以保持原样。

                        【讨论】:

                        • 这解决了我的问题。
                        【解决方案16】:
                        PS C:\> Set-ExecutionPolicy RemoteSigned
                        

                        对我有用

                        【讨论】:

                        • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
                        【解决方案17】:

                        只需删除 Power Shell 文件:

                        C:\Users\&lt;your account&gt;\AppData\Roaming\npm\**vue**

                        删除这个最后一个vue文件,这个文件的扩展名是power shall

                        删除运行命令后,它的工作。

                        【讨论】:

                          【解决方案18】:

                          在默认语言为德语的计算机上,错误可能如下所示:

                          vue : Die Datei "C:\Program Files\nodejs\vue.ps1" kann nicht geladen werden, da die Ausführung von Skripts auf diesem System deaktiviert ist. Weitere Informationen finden Sie unter "about_Execution_Policies"         
                          (https:/go.microsoft.com/fwlink/?LinkID=135170).
                          In Zeile:1 Zeichen:1
                          + vue --version
                          + ~~~
                              + CategoryInfo          : Sicherheitsfehler: (:) [], PSSecurityException
                              + FullyQualifiedErrorId : UnauthorizedAccess
                          

                          我必须搜索"vue" "PSSecurityException" 才能找到这个帖子。

                          我用 nvm-windows 安装了一个新的节点版本。然后我安装了 vue-cli。之后一个简单的vue --version 导致了上面的错误。

                          似乎删除 vue.ps1 文件有助于解决我的问题,就像上面一些用户建议的那样。

                          【讨论】:

                            【解决方案19】:

                            我在安装 grunt 和 yarn 时遇到了类似的问题。

                            "yarn : 文件 C:\AppData\Roaming\npm\yarn.ps1 无法加载。文件 C:\AppData\Roaming\npm\yarn.ps1 未进行数字签名。您无法在当前系统上运行此脚本。有关运行脚本的更多信息和
                            设置执行策略,请参阅 https://go.microsoft.com/fwlink/?LinkID=135170 上的 about_Execution_Policies。”

                            当我检查 AppData\Roaming\npm* 文件夹时,我可以看到 grunt 脚本生成为:

                            • Windows 命令脚本
                            • Windows Powershell 脚本

                            删除 powershell 脚本后,错误消失了。

                            【讨论】:

                              猜你喜欢
                              • 2017-04-28
                              • 2021-10-27
                              • 2013-05-03
                              • 2020-03-06
                              • 2021-02-22
                              • 2022-10-25
                              • 2020-06-20
                              • 2018-06-08
                              • 2013-10-06
                              相关资源
                              最近更新 更多