打字稿文件的编译问题

时间:2019-11-26 05:27:24

标签: typescript compiler-errors

我是TypeScript的新手,并尝试着解决这个问题。我使用.ts扩展名保存了文件,而不是将文件识别为Typescript文件,系统是将其识别为传输流文件。我已经使用node安装了所有的打字稿文件。每当我尝试编译代码时,显示的错误如下:

  

PS D:\ WorkSpace \ typescript> tsc basics.ts tsc:文件   C:\ Users \ mn \ AppData \ Roaming \ npm \ tsc.ps1无法加载,因为   在此系统上禁用了正在运行的脚本。有关更多信息,请参见   about_Execution_Policies位于   https://go.microsoft.com/fwlink/?LinkID=135170。

在第1行:1个字符:1

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

文件在文件夹中的显示方式如下:

Folder image

5 个答案:

答案 0 :(得分:3)

  1. 以RunAsAdministrator身份运行Windows PowerShell
  2. 键入Set-ExecutionPolicy Unrestricted
  3. 退出并再次运行编译器

答案 1 :(得分:2)

现在,我建议从npm bin文件夹中删除所有.ps1文件。

有时更改执行策略不是一个好习惯。更为严格的执行策略(RemoteSigned)可帮助用户无意中运行恶意代码。

该问题仍在npm / cli存储库中打开,标记为“需要讨论” Necessity of Powershell Script Support for Global Packages

答案 2 :(得分:0)

检查是否已全局安装Typescript。如果没有,请运行以下命令。

npm install -g typescript

答案 3 :(得分:0)

似乎您的脚本已被禁止executing_policy

以管理员身份运行PowerShell,然后尝试运行此命令:

Set-ExecutionPolicy Unrestricted

该命令将删除所有限制,之后您将能够运行任何Windows PowerShell脚本。

以下命令还用于编辑执行策略。

Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned - Only scripts signed by a trusted publisher can be run.
RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.

答案 4 :(得分:0)

  • CategoryInfo:SecurityError:(:) [],PSSecurityException
  • FullyQualifiedErrorId:UnauthorizedAccess

我在Visual Studio中遇到了相同的错误。但是使用命令提示符已解决

谢谢