An error occurs when using nodemon: "The file cannot be loaded... because running scripts is prohibited on this system"; Windows execution policy modification

The error content is as follows:
Insert image description here

The Windows system will impose a restriction on globally installed scripts to prevent malicious scripts from being executed, so an error will be reported here.

How to solve it? Resolve this issue by modifying the windows execution policy.

1. What is windows execution policy?

Windows sets something called an "execution policy" for PowerShell. In order to prevent some malicious scripts from running directly, the Windows system of general computers sets the execution policy to Restricted by default, which is restricted.

All execution strategies are as follows:

  • AllSigned: Requires all scripts and configuration files to be signed by a trusted publisher, including scripts written on the local machine. (Safe but locally written scripts also need to be signed, which is troublesome)
  • Bypass: Will not prevent you from running any scripts, and there are no prompts or warnings. (unsafe)
  • Default: The default execution policy;The default for ordinary desktop Windows is Restricted, and the default for server windows is RemoteSigned.
  • RemoteSigned: Requires that all scripts and configuration files downloaded from the Internet need to be signed by a trusted publisher. Local scripts do not need to be signed. Is the default execution policy for Windows servers. (safer)
  • Restricted: Unable to load configuration files or run scripts. The default execution policy for desktop Windows. (safe, but cannot run scripts)
  • Unrestricted: Allow all scripts to run.

To display execution policies for each scope in priority order, use Get-ExecutionPolicy -List .
Insert image description here
To see the effective execution policy for a PowerShell session, use Get-ExecutionPolicy without parameters.
Insert image description here

Windows execution policy reference: Learn/PowerShell/Scripting/Reference/Microsoft.PowerShell.Security

2. Solution

  1. Right-click the Windows key (lower left corner of the computer) and open PowerShell as administrator:
    Insert image description here

  2. You can check the current execution strategy first get-ExecutionPolicy, the result shows that it is restricted:
    Insert image description here

  3. Modify the execution strategy and enter the commandset-ExecutionPolicy RemoteSigned,
    The command here is actually not case-sensitive and can be written asset-executionpolicy remotesigned ;
    Insert image description here
    Enter A and click the enter key to confirm;
    Insert image description here

  4. To check whether the windows execution policy has been modified successfully, enter get-ExecutionPolicy and it will display that the modification was successful:
    Insert image description here

  5. Jyushin 执行 nodemon -v :
    Insert image description here

Guess you like

Origin blog.csdn.net/ThisEqualThis/article/details/129852672