tsconfig for typescript支持es5目标抛出错误

时间:2017-06-29 04:27:37

标签: angular ecmascript-5 typescript2.0 tsconfig es5-shim

我的tsConfig.json如下:

{
    "compilerOptions": {
        "target":"es5",
        "module":"system",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "sourceMap": true,
        "moduleResolution": "node",
        "lib": [ "es2015", "dom" ]
    },
    "exclude": [
        "node_modules"
    ]
}

但是当我尝试运行时npm start它会抛出我的错误

TS5023:未知的编译器选项' lib'。

所以当我从tsConfig中删除lib时:

  {
        "compilerOptions": {
            "target":"es5",
            "module":"system",
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "removeComments": false,
            "sourceMap": true,
            "moduleResolution": "node"
        },
        "exclude": [
            "node_modules"
        ]
    }

再次使用npm start

然后它开始抛出错误:

node_modules/@angular/common/src/directives/ng_class.d.ts(46,34): error TS2304: Cannot find name 'Set'.
node_modules/@angular/common/src/pipes/async_pipe.d.ts(44,38): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(369,30): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(415,30): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(416,20): error TS2304: Cannot find name 'Set'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(417,15): error TS2304: Cannot find name 'Set'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(418,246): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/directive_normalizer.d.ts(38,72): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/directive_normalizer.d.ts(40,74): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/metadata_resolver.d.ts(62,18): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/offline_compiler.d.ts(18,32): error TS2304: Cannot find name 'Map'.
node_modules/@angular/compiler/src/offline_compiler.d.ts(32,87): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/offline_compiler.d.ts(49,9): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/output/output_ast.d.ts(427,63): error TS2304: Cannot find name 'Set'.
node_modules/@angular/compiler/src/resource_loader.d.ts(13,23): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/runtime_compiler.d.ts(44,49): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/runtime_compiler.d.ts(46,65): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/util.d.ts(26,18): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/util.d.ts(27,46): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_init.d.ts(16,18): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(106,67): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(122,101): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(148,67): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(150,101): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(24,15): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(28,16): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/di/reflective_provider.d.ts(88,123): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/di/reflective_provider.d.ts(88,165): error TS2304: Cannot find name 'Map'.
...

奇怪但配置:

{
    "compilerOptions": {
        "target":"es6",
        "module":"system",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "sourceMap": true,
        "moduleResolution": "node"
    },
    "exclude": [
        "node_modules"
    ]
}

对我来说超级好。

但是目标是es6;我无法为IE等旧版浏览器进行转换。

专家可以在这看看吗?可能是一个我不知道的小问题。

非常感谢任何帮助。

了解更多信息:

>npm --version
3.10.10

>tsc --version
Version 2.3.4

>node --version
v6.10.2

0 个答案:

没有答案