skip to Main Content

I tried to use the global "nodemon" function in the powershell of Visual Studio Code. I am using Node.js. When I try to use the "nodemon" function, I get an error stating that "FileName 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." Does anyone know how to enable running scripts and resolve the issue?

I tried entering the file path after "nodemon" but I got the same error.

2

Answers


  1. You can use Set-ExecutionPolicy to do this:

    $ Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
    
    • -Scope CurrentUser sets the execution policy for the current user. Different values are available and listed here
    • -ExecutionPolicy Unrestricted sets the execution policy for the specified scope. All list of the possible values are listed here

    However, please be aware that this does have security implications, so only do this if you trust the scripts you want to run.

    To revert this change to block all scripts again, you can use

    $ Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Restricted
    

    For more information about execution policies: learn.microsoft.com

    Login or Signup to reply.
  2. Running scripts is sort of a security feature in powershell. Here are a list of the different types of running script execution policies:

    • Restricted: This is the default policy and prevents running any scripts. You can still use PowerShell for individual commands but cannot execute scripts.
    • AllSigned: This policy allows you to run scripts that have been digitally signed by a trusted publisher. Any unsigned scripts will not be executed.
    • RemoteSigned: This policy enables you to run locally-created scripts, while scripts downloaded from the internet must be signed by a trusted publisher to execute.
    • Unrestricted: This policy permits the execution of all scripts, regardless of their origin or whether they are signed. This setting may pose security risks, so use it with caution.

    If you aren’t going to be working with any potentially harmful or unknown script in powershell (nodemon isn’t one), you can set the policy to Unrestricted.

    You will need to open powershell as administrator, then paste in the following:

    Set-ExecutionPolicy Unrestricted

    You can change the Execution policy to whichever you desire but it may not fit the requirements of running nodemon.

    Set-ExecutionPolicy [Execution Policy Here]

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search