Skip to content

“expo init my-app” cannot be loaded because running scripts is disabled on this system

If you are getting errors like the following when you run the command to create project “expo init my-project”:
“File C:\Users\User\AppData\Roaming\npm\expo.ps1 cannot be loaded because running scripts is disabled on this system”

expo init my-app

“expo init my-app” cannot be loaded because running scripts is disabled on this system

The error message you are encountering “expo init my-app” indicates that running scripts is currently disabled on your system. This is a security measure in Windows PowerShell to prevent unauthorized execution of potentially harmful scripts.
To resolve this issue and allow the execution of scripts, you can change the execution policy to a less restrictive setting.

Follow these steps:

1.Open PowerShell as an administrator: Search for “PowerShell” in the start menu, right-click on “Windows PowerShell,” and choose “Run as administrator.
2. Run the following command “Set-ExecutionPolicy Unrestricted” in powershell and press enter. Explanations are below:

expo init my-app

Change the execution policy:

If you are not sure about the script change the execution policy to “RemoteSigned,” which allows local scripts to run and requires downloaded scripts to be signed, run the following command:

Set-ExecutionPolicy RemoteSigned

If you are sure about the scripts you execute that it is a safe script like in case of expo creating app we know its safe, you can set the execution policy to “Unrestricted” by running the following command into powershell:

Set-ExecutionPolicy Unrestricted

Press enter and now go to the terminal where you are running your app. After enabling script execution, try running expo init my-app again. It should work without the “running scripts is disabled” error.

If you do not know how to create expo project check the post: click here

Explanation:

The command Set-ExecutionPolicy RemoteSigned is used in Windows PowerShell to change the system’s script execution policy. Here’s what it does:

1. Execution Policy: An execution policy in PowerShell is a security feature that determines what kind of scripts can run on a Windows system.

2. RemoteSigned: When you set the execution policy to “RemoteSigned,” it means that PowerShell allows scripts to run, but they must be signed by a trusted publisher if they were downloaded from the internet or other remote locations.

In simpler terms, it’s a security measure. It ensures that scripts you create locally (on your own computer) can run without any issues. However, if you download a script from the internet, it won’t run unless it’s been digitally signed by the script author or a trusted source.

This helps prevent potentially harmful or malicious scripts from running on your system without your consent. It strikes a balance between security and flexibility for running scripts on your Windows computer.

Leave a Reply

Your email address will not be published. Required fields are marked *