How to fix error- nodemon.ps1 cannot be loaded because running scripts is disabled on this system, (without security risk)?

103,386

Solution 1

I'd recommend using RemoteSigned as opposed to Unrestricted, and limiting the policy to the CurrentUser if possible.

Run Powershell as Admin, and then:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

RemoteSigned: "The default execution policy for Windows server computers."



Other than that, I wouldn't worry about it too much, as it's not intended to be a security mechanism. See this quote from the docs:

"The execution policy isn't a security system that restricts user actions. For example, users can easily bypass a policy by typing the script contents at the command line when they cannot run a script. Instead, the execution policy helps users to set basic rules and prevents them from violating them unintentionally."

Solution 2

For those who are not aware of how to solve this error using Windows PowerShell

  1. Open PowerShell (Run As Administrator)
  2. Check the current execution policy using this command
    Get-ExecutionPolicy
    # You should get 'Restricted'
  1. Run this command to make it 'Unrestricted'
    Set-ExecutionPolicy Unrestricted
  1. Check again whether execution policy changed by running this command
    Get-ExecutionPolicy
    # You should get 'Unrestricted'
  1. Now try to run nodemon on your project
    nodemon 'filename.js'

Hope this would be helpful

Solution 3

Step 1 : Go to this location --> File C:\Users\Dell\AppData\Roaming\npm
Step 2 : Delete the nodemon.ps1 file and run the command.

Solution 4

There is no security risk whatsoever associated with allowing remoted signed scripts to run on your local machine. It basically means you can execute local unsigned scripts i.e scripts written by you while scripts from a remote source (nodemon in this case) must be signed by a trusted authority.

P.S: If you're on windows, you can just go to settings >> update and security >> for developers >> check the box beside change execution policy to allow local powershell scripts to run without signing

Solution 5

This command might help

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Share:
103,386
CyberKing
Author by

CyberKing

Full Stack JavaScript Developer

Updated on July 17, 2022

Comments

  • CyberKing
    CyberKing almost 2 years

    Error on terminal: nodemon.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.

    I have a solution to fix the issue by this way

    1. Open Windows PowerShell with Run as Administrator
    2. Run this command: Set-ExecutionPolicy Unrestricted

    That solves the issue, but this way the system shows Security Risk Warning. My question: Is there any other way to solve this without security risk? Target is to use nodemon.

  • derekbaker783
    derekbaker783 about 3 years
    Setting the execution policy to Unrestricted is unnecessary and non-optimal in this case, and is kind of a footgun.
  • derekbaker783
    derekbaker783 almost 3 years
    This answer doesn't add anything new
  • Salman Aziz
    Salman Aziz almost 3 years
    That worked for me and the serve is working with localhost:5000
  • derekbaker783
    derekbaker783 almost 3 years
    This answer doesn't add anything new (please see answers that preceded yours).
  • derekbaker783
    derekbaker783 almost 3 years
    This doesn't answer the question. At all.
  • derekbaker783
    derekbaker783 almost 3 years
    This doesn't add anything new. Please see Adarsh's answer (which preceded yours).
  • Tommy Hoang
    Tommy Hoang almost 3 years
    Is there anyway to set this policy by command promt?
  • derekbaker783
    derekbaker783 over 2 years
    @TommyHoang, run CMD as admin, then: cmd.exe /c powershell -command Set-ExecutionPolicy RemoteSigned
  • derekbaker783
    derekbaker783 over 2 years
    This answer doesn't add anything new. Please see the answers that preceded yours.
  • Laredo
    Laredo over 2 years
    Noticed there are two scripts there. One is a cmd script while the other is a powershell. With the powershell script deleted, it will default to the cmd script but you will notice a very minimal delay which is not noticeable persay
  • 4xMafole
    4xMafole over 2 years
    This saved my time. I appreciate very much.
  • Ahmed Hosny
    Ahmed Hosny over 2 years
    this is the easiest , and it worked , thanks
  • Matin
    Matin about 2 years
    This actually worked like a charm for me. Thanks!
  • Tuan Phan
    Tuan Phan about 2 years
    Work like a champ, ty mate.