create-react-app.ps1 cannot be loaded because running scripts is disabled on this system

avatar

Borislav Hadzhiev

Last updated: Mar 25, 2022

banner

Photo from Unsplash

create-react-app.ps1 cannot be loaded because running scripts is disabled on this system #

The error "create-react-app.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.

Open your PowerShell as an administrator and set its execution policy with the Set-ExecutionPolicy command.

shell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

The Set-ExecutionPolicy command sets the PowerShell execution policy for the Windows computer.

The 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.

Make sure to open your PowerShell as an administrator before you run the Set-ExecutionPolicy command.

If you aren't able to run the command as an administrator, try running it with the CurrentUser parameter.

shell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

The RemoteSigned policy still prevents us from running unsigned scripts.

Now, run the Get-ExecutionPolicy command:

shell
Get-ExecutionPolicy

The Get-ExecutionPolicy command should display the effective execution policy for the current PowerShell session (RemoteSigned).

If you get RemoteSigned back, then you have successfully updated your permissions and are able to run the create-react-app command.

You can also run the command with the -List parameter to display the execution policies for each scope in the order of precedence.

shell
Get-ExecutionPolicy -List
When ran with the -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).

Alternatively, you can try running the create-react-app command with the npx prefix:

shell
# 👇️ clear the npx cache npx clear-npx-cache # 👇️ for normal React.js project npx create-react-app my-app # 👇️ for TypeScript React.js project npx create-react-app my-app --template typescript

If the error persists, try to delete the C:\Users\Your_User_Name\AppData\Roaming\npm\create-react-app.ps1 file and restart your terminal.

Make sure to replace the Your_User_Name placeholder with your actual username.

After restarting your terminal, try running the command again.

If that doesn't help, clear your npm cache and re-run the command.

shell
# 👇️ clean npm cache npm cache clean --force

If none of the suggestions worked, you can try to set the execution policy to Unrestricted, which means that the system would allow unsigned PowerShell scripts to run.

shell
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Starting with PowerShell 6.0, Unrestricted is the default execution policy for non-Windows computers and can't be changed.

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.

Conclusion #

The error "create-react-app.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.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.