问题
I am following the AngularJS start guide using Sublime. When I try to compile, I get the following error:
/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]
The other problem is that it seems sublime can't recognize the path and import properly. It's showing me some error in the editor. How can I config this to make it work? Thank you very much!!!
- Sample on GitHub
tsconfig.json
{ "compilerOptions": { "out": "built/out.js", "sourceMap": true, "target": "es5" }, "files": [ "app.ts" ] }
回答1:
Have you configured TS compiler in sublime?
1st error: Provide module flag to compiler. Ex: tsc -m commonjs
. (Compiler Options).
2nd error: Target ECMAScript5 -t es5
. By default the compiler targets ECMAScript 3, the current prevailing standard.
3rd error: Add --experimentalDecorators flag to compiler.
I've downloaded sample from ng-conf and applied this tsconfig (for 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"
}
}
Update
1st red underline: Cannot find module 'angular2/angular2'
2nd:red under line: Your config misses experimentalDecorators
. I've told you to add this in original answer. Take a look into my tsconfig.json
回答2:
These settings worked for me, all errors are gone.
{
"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"
}
}
来源:https://stackoverflow.com/questions/31767603/configuring-sublime-3-to-build-typescript