Introduction
When you are creating a SharePoint SPFx project for the first time by running the following command "yo @microsoft/sharepoint", you may receive an error that will block the creation of the project:
"File C:\Users\user\AppData\Roaming\npm\ng.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"
Solution
This error occurs when running PowerShell scripts is disabled in your development environment in this case the Yeoman commands are not allowed for security reasons, this could be due to the current user having an undefined ExecutionPolicy. To allow Yeoman scripts, open PowerShell with administrative rights then apply the following steps:
Step 1
Run this command:
set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Step 2
Now, you can view the list of policies with their status by running the following command in PowerShell:
Get-ExecutionPolicy -list
As you can see this is the execution policy list in your development environment. It should show "RemoteSigned" for the "CurrentUser"
Scope ExecutionPolicy
- ----- ---------------
- MachinePolicy Undefined
- UserPolicy Undefined
- Process Undefined
- CurrentUser RemoteSigned
- LocalMachine AllSigned
Now, this should solve the permission issue and you can try to execute the Yeoman command again to create the SharePoint SPFx project.