【问题标题】:Configuring Sublime 3 to Build TypeScript配置 Sublime 3 以构建 TypeScript
【发布时间】:2016-01-20 12:41:25
【问题描述】:

我正在使用 Sublime 关注 AngularJS start guide。当我尝试编译时,出现以下错误:

/Users/Audrey/MyDev/node/07tsdemo/app.ts(2,1): error TS1148: Cannot compile modules unless the '--module' flag is provided.
/Users/Audrey/MyDev/node/07tsdemo/app.ts(4,1): error TS1205: Decorators are only available when targeting ECMAScript 5 and higher.
/Users/Audrey/MyDev/node/07tsdemo/app.ts(11,7): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.
[Finished in 2.2s with exit code 2]
[cmd: ['tsc', '/Users/Audrey/MyDev/node/07tsdemo/app.ts']]
[dir: /Users/Audrey/MyDev/node/07tsdemo]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

另一个问题是 sublime 似乎无法识别路径并正确导入。它在编辑器中向我显示了一些错误。我该如何配置它以使其工作?非常感谢!!!

  1. GitHub 上的示例
  2. tsconfig.json

    {
        "compilerOptions": {
            "out": "built/out.js", 
            "sourceMap": true, 
            "target": "es5"
        }, 
        "files": [
            "app.ts"
        ]
    }
    

【问题讨论】:

  • 您使用的是什么构建系统?你安装了哪些插件?编译器是否在监视模式下运行?当您尝试导入时,编辑器中的“一些错误”的全文是什么?您的问题目前还不清楚,请edit 它并尽可能多地添加有关您的设置以及您遵循的步骤的详细信息。

标签: angularjs typescript sublimetext3


【解决方案1】:

你在 sublime 中配置过 TS 编译器吗?

第一个错误:向编译器提供模块标志。例如:tsc -m commonjs。 (Compiler Options)。

第二个错误:目标 ECMAScript5 -t es5。默认情况下,编译器以 ECMAScript 3 为目标,这是当前的主流标准。

第三个错误:将 --experimentalDecorators 标志添加到编译器。

我从 ng-conf 下载了示例并应用了这个 tsconfig(适用于 Windows):

{
    "cmd": ["tsc","$file"],
    "path": "C:/Users/Artiom/AppData/Roaming/npm",
    "compilerOptions": {
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true, //add this to your config.
        "module": "commonjs", 
        "target": "es5"
    }
}

更新

第一个红色下划线:找不到模块'angular2/angular2'

第二个:红色下划线:您的配置错过了experimentalDecorators。我已经告诉您将其添加到原始答案中。看看我的 tsconfig.json

【讨论】:

  • 非常感谢 Artiom。构建完成,我可以看到最终的 js 文件。但不知何故,崇高仍然显示错误下划线。你知道如何让它消失吗?另外,你有我可以用于 Angular 2 的 sublime 构建配置文件吗?再次感谢
  • @AudreyLi 提供样本下载。 Ant现在显示什么样的错误?三个都和原来的问题一样?
  • 请提供您的tsconfig.json
  • 我按照您的指南进行了更多挖掘。我使用this build。现在 sublime 编译好了。但是 sublime 仍然有一些红色错误underline。我想知道是不是因为它无法识别导入模块。测试项目为here
  • @AudreyLi 更新了答案。请再看一下我的配置。
【解决方案2】:

这些设置对我有用, 所有错误都消失了。

{
     "cmd": ["tsc",
     "--module","system",
     "--experimentalDecorators",
     "--target","ES5",
     "--moduleResolution","node",
     "$file"],
     "file_regex": "^(.+?) \\((\\d+),(\\d+)\\)(: .+)$",
     "line_regex": "\\((\\d+),(\\d+)\\)",
     "selector": "source.ts",
     "osx": {
     "path": "/usr/local/bin:/opt/local/bin"
     }
}

【讨论】:

  • 好的,但是这是什么文件?
猜你喜欢
  • 2012-09-28
  • 2018-06-16
  • 2014-12-28
  • 1970-01-01
  • 1970-01-01
  • 2014-07-07
  • 2015-08-04
  • 2013-07-08
  • 2015-11-23
相关资源
最近更新 更多