Last updated: Apr 4, 2024
Reading time·4 min
The error "yarn.ps1 cannot be loaded because running scripts is disabled on this system" occurs when the execution policy does not allow running the specific script on Windows.
Use the Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
command to solve
the error.
yarn : File C:\Users\bobbyhadz\AppData\Roaming\npm\yarn.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.
Open your PowerShell as an administrator and set its execution policy with the Set-ExecutionPolicy command.
To run PowerShell as an administrator:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
The Set-ExecutionPolicy
command sets the PowerShell execution policy for the
Windows computer.
RemoteSigned
execution policy is the default execution policy for Windows server computers. It requires that all scripts and configuration files that were downloaded from the internet are signed by a trusted publisher.This effectively removes the execution policy of Restricted
, which doesn't
allow us to load configuration files or run scripts. The Restricted
execution
policy is the default for Windows client computers.
Set-ExecutionPolicy
command.CurrentUser
parameterIf you aren't able to run the command as an administrator, try running it with
the CurrentUser
parameter.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
The RemoteSigned
policy still prevents us from running unsigned scripts.
Now, run the Get-ExecutionPolicy command:
Get-ExecutionPolicy
The Get-ExecutionPolicy
command should display the effective execution policy
for the current PowerShell session (RemoteSigned
).
RemoteSigned
back, then you have successfully updated your permissions and are able to run the yarn
command.You can also run the command with the -List parameter to display the execution policies for each scope in the order of precedence.
Get-ExecutionPolicy -List
-List
parameter, the command returns a list of all execution policy values for the session listed in precedence order.The command should show that the RemoteSigned
policy is set for the default
scope (LocalMachine
).
Unrestricted
If nothing else works, you can try to set the execution policy to
Unrestricted
, which means that the system would allow unsigned PowerShell
scripts to run.
To run PowerShell as an administrator:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Starting with PowerShell 6.0, Unrestricted
is the default execution policy for
non-Windows computers and can't be changed.
Alternatively, you can run the command scoped only to the current user.
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
If I run the Get-ExecutionPolicy -List
command, I can see that the execution
policy for the LocalMachine
scope is now set to Unrestricted
.
Get-ExecutionPolicy -List
The policy loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the internet, you would still get prompted for permission before it runs.
ExecutionPolicy
to Bypass
Alternatively, you can set your ExecutionPolicy
to Bypass
.
When using the Bypass
policy, nothing is blocked and there are no warnings or
prompts. Bypass is more permissive than Unrestricted
.
Make sure to open PowerShell as an administrator before issuing the command.
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
You can also bypass the policy for a specific script (.ps1
) file.
powershell -ExecutionPolicy Bypass -File "C:\path\to\script.ps1"
The possible execution policy values are the following.
Name | Description |
---|---|
AllSigned | Requires that all scripts and configuration files are signed by a trusted publisher. |
Bypass | Nothing is blocked and there are no warnings or prompts. |
Default | Sets the default execution policy (Restricted for Windows clients). |
RemoteSigned | Requires that all scripts and configuration files downloaded from the internet are signed by a trusted publisher. |
Undefined | No execution policy is set for the scope. |
Unrestricted | The default policy since PowerShell 6.0 for non-Windows computers. The policy loads all configuration files and runs all scripts. If you run an unsigned script, you're prompted before the script runs. |
You can read more about the Set-ExecutionPolicy
command and its possible
values and parameters in
this section
of the official docs.
If you get an error that yarn is not found or is not recognized, click on the related article.