The error content is as follows:
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
.
To see the effective execution policy for a PowerShell session, use Get-ExecutionPolicy
without parameters.
Windows execution policy reference: Learn/PowerShell/Scripting/Reference/Microsoft.PowerShell.Security
2. Solution
-
Right-click the Windows key (lower left corner of the computer) and open PowerShell as administrator:
-
You can check the current execution strategy first
get-ExecutionPolicy
, the result shows that it is restricted:
-
Modify the execution strategy and enter the command
set-ExecutionPolicy RemoteSigned
,
The command here is actually not case-sensitive and can be written asset-executionpolicy remotesigned
;
EnterA
and click the enter key to confirm;
-
To check whether the windows execution policy has been modified successfully, enter
get-ExecutionPolicy
and it will display that the modification was successful:
-
Jyushin 执行
nodemon -v
: