Tag Archives: VScode powershell Run ts-node Error

[Solved] VScode powershell Run ts-node Error: Unable to load file xxxx…

vscode powershell running ts-node reports an error

Recurrence : In window10, ts-node is installed globally on the external CMD , and execution of ts-node -v shows that the version number is installed successfully. Open the terminal in vscode , create a new ts file and use ts-node test.ts to report an error.

ts-node : Unable to load file xxxx because running scripts is prohibited on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

Location Line: 1 Character: 1

+ ts-node 07.ts

+ ~~~~~~~

    + CategoryInfo : SecurityError: (:)[], PSSecurityException

+ FullyQualifiedErrorId : UnauthorizedAccess

Reason : The script running on cmd cannot run on powershell , and the execution policy of powershell restricts its execution.

Solution : View the execution policy of powershell and change the execution policy for the user

Execute the command to view the execution policy:  Get-ExecutionPolicy -List

Briefly explain:

userPolicy — Computer current user group policy settings

Process —   This scope only affects the current powershell session, the execution policy is not saved in the registry, and it is deleted when it is closed. (Refer to sessionStorage to understand)

CurrentUser — The execution policy affects only the current user, which is stored in the HKEY_CURRENT_USER registry

LocalMachine — Execution policy affects all users on the current computer and is saved in the registry

 

Change the execution policy of CurrentUser

Set-ExecutionPolicy -ExecutionPolicy <PolicyName> -Scope <scope>

Change CurrentUser to RemoteSigned here .

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Review the execution strategy again

 

It’s ok now