Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilation issue with typescript file

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

like image 508
mn3094 Avatar asked Nov 26 '19 05:11

mn3094


People also ask

What happens when TypeScript is compiled?

The TypeScript compiler compiles these files and outputs the JavaScript with . js extension by keeping the same file name as the individual input file. The TypeScript compiler also preserves the original file path, hence the . js output file will be generated where the input file was in the directory structure.

Does TypeScript require compilation?

To get the JavaScript files for the TypeScript modules, we need to compile modules using TypeScript compiler. Compilation of a module depends on the target environment you are aiming for. The TypeScript compiler generates the JavaScript code based on the module target option specified during compilation.

Why does TypeScript need to be compiled?

Browsers don't understand TypeScript. They understand JavaScript code. Hence, the TypeScript code needs to get compiled into JavaScript, and for that, you need the TypeScript compiler. You can install TypeScript globally using the following npm command.


2 Answers

  1. Run the Windows PowerShell as RunAsAdministrator
  2. type Set-ExecutionPolicy Unrestricted
  3. exit and run compiler again
like image 139
Javid Sattar Avatar answered Sep 29 '22 00:09

Javid Sattar


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.

like image 22
David Donari Avatar answered Sep 29 '22 00:09

David Donari