在 npm 更新包之后,无法加载 ps1,因为在这个系统上禁用了运行脚本

我设计的 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

火炉 + Category oryInfo: SecurityError: (:)[] ,PSSecurityException + FullyQualifiedErrorId: 未授权访问

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

假设这个问题与 firebase 有关——我一直在使用这些工具,但现在已经更新了 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

+ Category oryInfo: SecurityError: (:)[] ,PSSecurityException + FullyQualifiedErrorId: 未授权访问

VSCode 版本: 版本: 1.37.1(用户设置) 提交: f06011a 日期: 2019-08-15T16:17:55.855 Z 电子: 4.2.7 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8:6.9.427.31-电子 OS: Windows _ NT x6410.0.18362 操作系统版本: Windows10主页 1903年版本 OS build-18362.295

我一直在阅读和看到许多线程围绕脚本的权限,但我没有改变任何-的确,PowerShell 脚本工作直到我更新我的包。同时没有其他设置。我不想不必要地更改 PowerShell 设置。

177026 次浏览

This is a powershell security policy, to fix it, run Powershell as administrator and run the following

PS C:\> Set-ExecutionPolicy RemoteSigned

If you don't want to run the command as an administrator but just for the current user, you can add a scope like below

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

The stricter the policy, the more secure your system becomes.

You can change RemoteSigned to other options like: Restricted, AllSigned, RemoteSigned, Unrestricted

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

Alternatively you can modify C:\Program Files\PowerShell\7\powershell.config.json using a text editor and add or modify the following section.

{
....


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

Also, one thing worth mentioning is that you need to open PowerShell as Admin and then change the policy like so.

PS C:\> Set-ExecutionPolicy RemoteSigned

Reference - Using the Set-ExecutionPolicy Cmdlet

Just delete firebase.ps1 file:

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

I don't know if it can help with Firebase but I had a similar problem installing Vue with *>npm install -g @vue/cli* .

Long story short:
I deleted vue.ps1 from C:\Users\XXX\AppData\Roaming\npm\ and installed it locally (without -g) from powershell terminal inside VsCode *>npm install @vue/cli*.
After that I could use Vue commands without problems.

A little clarification: when you run PowerShell as Admin, in most cases you don't need to note a path. Just type:

Set-ExecutionPolicy RemoteSigned

then press "A", then "Enter"

This could be due to the current user having an undefined ExecutionPolicy.

You could try the following

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

File C:\Users\xxxx\AppData\Roaming\npm\vue.ps1 cannot be loaded because running scripts is disabled on this system.

I had the same error message with vue. After running the below command successfully

npm install -g @vue/cli

when i ran commands like vue or vue --version, i received that error message.

This is how i fixed it: I pressed the buttons windows + E, clicked view, checked hidden items. Then, i went to C:\Users\xxxx\AppData\Roaming\npm folder and deleted the vue file of type 'windows powershell script'. After that, i ran the commands vue and vue --version succesfully. Hope this helps.

I also had this problem in the powershell and i used the following : then i again installed the serve package.

 Set-ExecutionPolicy -Scope CurrentUser

and then i chose Unrestricted and gave serve command and it worked.

I didn't have any problem with npm but the same problem is in the using yarn on windows. In my case, I deleted yarn.ps1 and it worked fine for me:

File path:

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

On a computer with German as the default language the error might look like:

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

I had to search for "vue" "PSSecurityException" to find this thread.

I installed a new node version with nvm-windows. Then I installed vue-cli. After that a simple vue --version led to the error above.

It seems like the removal of the vue.ps1 file helped to resolve my problem like some users suggested above.

I had a similar issue during installation of grunt and yarn.

"yarn : File C:\AppData\Roaming\npm\yarn.ps1 cannot be loaded. The file C:\AppData\Roaming\npm\yarn.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and
setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170."

When I checked the AppData\Roaming\npm* folder, I could see grunt script being generated as:

  • Windows Command Script
  • Windows Powershell Script

Upon deletion of the powershell script, the error was gone.

Instead of using PowerShell and changing its security settings, you can simply use cmd instead. It will not give an error and your all commands will run smoothly.

Remember PowerShell is stronger and sensitive. So, Microsoft by default disables running .ps1 files as it can cause a security issue and harm your pc. So, that's why you should try to use cmd instead of changing PowerShell security.

Just delete Power Shell file:

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

Delete this last vue file, extension of this file is power shall

after delete run command it's work.

Open Powershell and execute this command:

set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Delete firebase.ps1 located in:

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

In case you don't have firebase.ps1 delete vue.ps1

enter image description here

Open Powershell from your VS code and then execute this command on that:

set-ExecutionPolicy RemoteSigned -Scope CurrentUser

this worked for me. it will ask you for CLI authentication.

For those who work with VS Code and get the about_Execution_Policies error. In my case with the command ncu -u (npm-check-updates).

Try it with CMD:

enter image description here

Simply execute the command in CMD again.

If this works, the security settings can remain as they are.

PS C:\> Set-ExecutionPolicy RemoteSigned

It's works for me

If you have this issue in VS Code, close PowerShell terminal and open a Command Prompt terminal instead.

  1. search for powershell

  2. right click and run as administration

  3. run this simple command Set-ExecutionPolicy RemoteSigned

  4. Press A And Enter

  5. go to code and run yarn add <YOUR_MODULE>

  6. press Enter.

congratulations now it would be done.

Just open cmd as administrator and go to your project

then execute your firebase command