配置 Sublime 3 以构建 TypeScript
Configuring Sublime 3 to Build TypeScript
我正在使用 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好像不能正确识别路径和导入。它向我展示了编辑器中的一些错误。我该如何配置才能使其正常工作?非常感谢!!!
- 样本 GitHub
tsconfig.json
{
"compilerOptions": {
"out": "built/out.js",
"sourceMap": true,
"target": "es5"
},
"files": [
"app.ts"
]
}
你在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
这些设置对我有用,
所有错误都消失了。
{
"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"
}
}
我正在使用 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好像不能正确识别路径和导入。它向我展示了编辑器中的一些错误。我该如何配置才能使其正常工作?非常感谢!!!
- 样本 GitHub
tsconfig.json
{ "compilerOptions": { "out": "built/out.js", "sourceMap": true, "target": "es5" }, "files": [ "app.ts" ] }
你在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
这些设置对我有用, 所有错误都消失了。
{
"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"
}
}