Resolved
Encountering the error message "tsc.ps1 cannot be loaded because running scripts is disabled on this system" typically indicates that the execution policy restricts running a specific script on Windows.
To address this issue, there are three possible solutions:
- Resolve the error by using the command
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
.
To implement this solution, launch PowerShell as an administrator and set the execution policy with the Set-ExecutionPolicy command.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
If executing the command as an admin proves challenging, attempt running it with the CurrentUser parameter.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Utilize the Get-ExecutionPolicy
command to verify the current session's execution policy (RemoteSigned) following any changes made.
Get-ExecutionPolicy
- Add .cmd to the command
Appending .cmd to the command instructs PowerShell to utilize the cmd version instead.
tsc.cmd -v
tsc.cmd --init
tsc.cmd myFile.ts
- You might also opt for prefixing the
tsc
command with npx
The npx
prefix serves as an npm package runner capable of executing packages from the npm registry without requiring installation.
npx tsc -v
npx tsc --init
npx tsc myFile.ts
For further insights, refer to