Here are the steps to fix the issue persistently:
-
Open PowerShell as Administrator:
- Search for "PowerShell" in the Start menu.
- Right-click it.
- Select Run as Administrator.
-
Check Current Execution Policy:
- Run this command in PowerShell:
Get-ExecutionPolicy -List - This shows policies for different scopes.
- Run this command in PowerShell:
-
Set Persistent Execution Policy:
-
To allow scripts for your user account persistently:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -
This setting applies only to your user account.
-
It remains active after you restart your computer.
-
Answer 'Y' (Yes) if prompted to confirm the change.
-
Alternatively, to allow scripts for all users persistently (requires administrator privileges):
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Bypass -
This setting applies to all users on the computer.
-
It remains active after restarts.
-
Answer 'Y' (Yes) if prompted.
-
Choose the scope (
CurrentUserorLocalMachine) that best fits your needs.CurrentUseris often sufficient and safer.
-
-
Run Your Command Again:
- Retry your
npm init playwrightcommand. - It should run without the execution policy error.
- Retry your
Additional Notes:
- Using
Bypasslets any script run. Understand the security risk before proceeding. - If problems continue, consider reinstalling Node.js. Get the latest version from the Node.js website.
where is the powershell?