Search code examples
node.jspowershellweb-development-servernodemon

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


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://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2

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.


Solution

  • 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."