Why Vercel CLI is Not Working on My Windows Laptop: Modifying Execution Policies
Nitish Kumar Singh
Mar 11, 2024Hello developers! In this blog post, I am going to describe an issue and how I resolved it, which is about Windows PowerShell Execution Policies.
A day ago, when I had completed adding a feature to my website and ran the command vercel
to deploy changes, I encountered an error with the message: "vercel: File C:\Users\userId\AppData\Roaming\npm\vercel.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
".
Then I learned about such a safety feature in the Windows system, which is PowerShell's execution policy. What is PowerShell's execution policy? According to Microsoft Docs: "PowerShell's execution policy is a safety feature that controls the conditions under which PowerShell loads configuration files and runs scripts. This feature helps prevent the execution of malicious scripts".
To run Vercel CLI and execute the command vercel
, it is necessary to first load Vercel CLI's configuration file, which is "vercel.ps1
". But because running scripts is disabled by default on Windows systems, we need to enable running scripts by modifying the Execution Policy.
Before we learn how to modify the execution policy, let's understand more about it. In Windows, the execution policy isn't a security system that restricts users' actions. Instead, it helps us set basic rules and prevents us from unintentionally violating them.
We can set the following execution policies for running scripts in PowerShell according to our requirements:
- AllSigned: Runs all scripts and configuration files that are signed by trusted publishers and asks before running scripts that are not marked as trusted.
- Bypass: Runs all scripts and configuration files without any restrictions and there are no warnings or prompts.
- Default: Sets the default execution policy, which is Restricted for Windows clients and RemoteSigned for Windows servers.
- RemoteSigned: Same as AllSigned but for server computers.
- Restricted: This is the default policy that is set in Windows computers that we use physically, and this is the problem of our error.
- Undefined: There is no execution policy set in the current scope.
- Unrestricted: This is the default execution policy for non-Windows computers and cannot be changed. Unsigned scripts can run, and there is a risk of running malicious scripts.
Execution policy scope: We can set an execution policy that is effective only in a particular scope. The valid values for Scope are MachinePolicy, UserPolicy, Process, CurrentUser, and LocalMachine. LocalMachine is the default scope when we are setting an execution policy without specifying scope, and their meaning or effectiveness is the same as their name.
To check the effective execution policy for the current PowerShell session, run the Get-ExecutionPolicy
command:
Get-ExecutionPolicy
To check all of the execution policies for all scopes that affect the current session and display them in precedence order, run the below command:
Get-ExecutionPolicy -List
We can change the execution policy (therefore it is not a security feature) for a particular scope using PowerShell by running the command below:
Syntax: Set-ExecutionPolicy -ExecutionPolicy <PolicyName> -Scope <scope>
Example: Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope CurrentUser
To resolve my problem, I first changed the execution policy for CurrentUser to AllSigned and ran the vercel command, then it showed the error: "vercel.ps1
is not digitally signed", so I changed it to Unrestricted, and the issue was resolved.
So, this is the issue I had faced and resolved. I hope this post helps you to resolve this issue if you are in it or find this post helpful and informative. Happy coding!