VSC PowerShell. After npm updating packages .ps1 cannot be loaded because running scripts is disabled on this system

135,783

Solution 1

Just delete firebase.ps1 file:

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

Solution 2

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"
}

Solution 3

  1. search for powershell
  2. right click and run as administration
  3. run this simple command Set-ExecutionPolicy RemoteSigned
  4. Press A And Enter

Solution 4

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"

Solution 5

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

Share:
135,783
Aponting
Author by

Aponting

Updated on July 08, 2022

Comments

  • Aponting
    Aponting almost 2 years

    I design websites in VSC and PowerShell is my default terminal.

    After updating and deploying a website to firebase earlier, I was prompted to update firebase tools - which I did using npm. Immediately after I cannot run/access any firebase scripts wthout the folllowing error:

    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

    I've spent a few hours searching around and can't find a solid answer the problem. Many threads are several years old and I find it bizarre I've not had this problem in the past year until today. I can still access firebase scripts if I set my default terminal to cmd.

    Assuming the problem was related to firebase-tools I've carried on working but have now updated vue.js and get the error again when trying to run any vue commands in powershell:

    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

    I've been reading around and seen many threads around permissions for scripts, but I haven't changed any - indeed the PowerShell scripts worked right up until I updated my packages. No other settings touched in the mean time. I don't want to be changing PowerShell settings unnecessarily.

  • Aponting
    Aponting over 4 years
    Thanks for the reply. I had actually already come across that website and am reluctant to change anything as the error came about without me changing anything or installing/restarting the computer. I have now changed my settings in PowerShell and it runs scripts as before, is there anything I should be concerned with having changed this? I originally posted the question on gitHub and a couple of people have the same issue. github.com/firebase/firebase-tools/issues/1627
  • tushortz
    tushortz over 4 years
    @Aponting As long as you don’t have malicious software on your pc that may route data to an external server, it should be fine. Better to also have an antivirus installed but I don’t think it’s too much to worry about if you don’t use dodgy websites or software
  • Tech User
    Tech User over 4 years
    i dont have firebase.ps1 in \AppData\Roaming\npm folder
  • Sergei Zahharenko
    Sergei Zahharenko over 4 years
    helped to me as well... in my case it was vue.ps1, just removed it and all worked well...
  • Admin
    Admin about 4 years
    Executing Set-ExecutionPolicy RemoteSigned in the windows powershell works now. Thank you.
  • Aponting
    Aponting almost 4 years
    As an update - I regularly get the error after updating firebase & vue and so delete the relevant .ps file each time without issues as I'm reluctant to alter script settings
  • Admin
    Admin almost 4 years
    in my case it was touch.ps1, moved it from there and it works now! nO iDeA if what i did is right or wrong
  • Kamran Mushtaq
    Kamran Mushtaq over 3 years
    I was facing the same issue with http-server.ps1 deleting the file resolved the problem
  • Imran_Developer
    Imran_Developer about 3 years
    100% works for me. It may be either firebase.ps1 or vue.ps1, just delete it.
  • Felipe Chagas
    Felipe Chagas almost 3 years
    Worked as well, in my case it was the file yarn.ps1
  • Hamza Dahmoun
    Hamza Dahmoun over 2 years
    Worked for me, I had the same issue but with Vue.
  • Admin
    Admin over 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
  • Pooja
    Pooja over 2 years
    This solve my issue.
  • tahmasib
    tahmasib over 2 years
    Why does it work after deleting the .ps1 and why .ps1 file causing this issue?
  • RUGVED
    RUGVED over 2 years
    Yes this works for me too