【问题标题】:Angular2: Many errors compiling to ES5Angular2:编译到 ES5 的许多错误
【发布时间】:2016-08-01 08:19:48
【问题描述】:

在 tsconfig.json 文件中设置为 es5 时,我无法编译我的 angular 2 应用程序。如果我将其更改为 es6,我的所有编译器错误都会消失。

tsconfig:

"compilerOptions": {
    "target": "es5",
    "module": "system",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "moduleResolution": "node"
  },
  "files": [ ... 

索引.html

<script src="~/node_modules/systemjs/dist/system.src.js"></script>
    <script src="~/node_modules/es6-shim/es6-shim.min.js"></script>
    <script src="~/node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="~/node_modules/moment/min/moment.min.js"></script>
    <script>
        System.config({
            defaultJSExtensions: true,
            baseURL: '/ECAV.Admin/node_modules',
            packages: {
                'app': { format: 'register', defaultExtension: 'js' },
                'rxjs': { defaultExtension: 'js' }
            },
            paths: {
                'angular2/*': 'angular2/*',
                'rxjs': 'rxjs/bundles/Rx.js',
                'linqsharp': 'linqsharp/built/linqsharp',
                'highcharts': 'highcharts',
                'ng2-highcharts': 'ng2-highcharts/ng2-highcharts',
                'lodash': 'lodash/lodash'             
            },
            map: {
                moment: 'moment/moment.js'
            }
        });
    </script>
    <script src="/Admin/node_modules/rxjs/bundles/Rx.js"></script>
    <script src="/Admin/node_modules/angular2/bundles/angular2.dev.js"></script>
    <script src="/Admin/node_modules/lodash/lodash.js"></script>

错误示例(库类中有很多错误):

Build: Cannot find name 'Set'.  Admin   C:\dev\ecav\Admin\node_modules\angular2\src\common\directives\ng_class.d.ts 72  

我的一个需求是在IE11中运行这个网站,所以我需要es5。

任何帮助将不胜感激。

【问题讨论】:

  • 为什么要在 tsconfig.json 文件中定义 files 块,它包含什么?谢谢!
  • 它们是我想要在 dist 中的文件的路径,因为由于各种原因,我想省略一些文件,规格等。 "files": [ "typings/browser.d.ts" ,“app/boot-main.ts”,但是,当我删除文件条目时,我得到了相同的行为。我无法将代码编译为 es5。我可以在 SystemJS 中使用 Babel 转译器吗?谢谢蒂埃里:)

标签: typescript angular


【解决方案1】:

如果您要转译为 ES5,您可能需要在您的主要打字稿文件中设置 ///&lt;reference path="node_modules/angular2/typings/browser.d.ts"/&gt;

发件人:https://stackoverflow.com/a/35737470/3279156

【讨论】:

  • 谢谢你,你是救命稻草!
猜你喜欢
  • 1970-01-01
  • 2016-10-20
  • 1970-01-01
  • 2017-10-13
  • 2017-02-08
  • 2011-12-19
  • 2017-03-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多