Configuring Sublime 3 to Build TypeScript

天大地大妈咪最大 提交于 2020-01-14 03:05:08

问题


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!!!

  1. Sample on GitHub
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!