9

I'm new to typescript and was trying to work on it where in I came across this issue, where I saved a file using .ts extension and instead of recognizing the file as a typescript file,the system is recognizing it as a Transport Stream file. I have already installed all the typescript files using node. Whenever I try to compile the code the error displayed is as follows:

PS D:\WorkSpace\typescript> tsc basics.ts tsc : File C:\Users\mn\AppData\Roaming\npm\tsc.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.

At line:1 char:1

  • tsc basics.ts
  • + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
    

This is how the file appears in the folder:

Folder image

4 Answers 4

10
  1. Run the Windows PowerShell as RunAsAdministrator
  2. type Set-ExecutionPolicy Unrestricted
  3. exit and run compiler again
Sign up to request clarification or add additional context in comments.

Comments

5

For now, I suggest removing all .ps1 files from your npm bin folder.

Sometimes changing the execution policy is not a good practice. A more restricted Execution policy (RemoteSigned) helps users from unintentionally running malicious code.

The issue is still open in the npm/cli repository, labeled as 'Needs Discussion' Necessity of Powershell Script Support for Global Packages.

1 Comment

For me, the tsc.ps1 it was in C:\Users\xxx\AppData\Roaming\npm
0
  • CategoryInfo : SecurityError: (:) [], PSSecurityException
  • FullyQualifiedErrorId : UnauthorizedAccess

I got the same error in visual studio. But using command prompt it has been solved

Thank you

Comments

0

I would suggest not changing the ExecutionPolicy, as it would open the door for any vendor to run scripts on your machine.

The file that is being run is: C:\Users%USERNAME%\AppData\Roaming\npm\tsc.ps1

Removing it, or renaming it will make the tsc command target C:\Users%USERNAME%\AppData\Roaming\npm\tsc.cmd instead.

This did the trick for me.

Answer found in: https://github.com/microsoft/TypeScript/issues/35606 by user sinaAtabaki

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.