我使用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无法识别路径并正确导入。它在编辑器中显示了一些错误。如何配置它以使其工作?非常感谢!!!
tsconfig.json
{
"compilerOptions": {
"out": "built/out.js",
"sourceMap": true,
"target": "es5"
},
"files": [
"app.ts"
]
}
答案 0 :(得分:1)
您是否在sublime中配置了TS编译器?
第一个错误:向编译器提供模块标志。例如:tsc -m commonjs
。 (Compiler Options)。
第二个错误:目标ECMAScript5 -t es5
。默认情况下,编译器以ECMAScript 3为目标,这是当前的主流标准。
第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
答案 1 :(得分:0)
这些设置对我有用, 所有的错误都消失了。
{
"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"
}
}