2

I cannot compile my angular 2 application when set to es5 in the tsconfig.json file. If i change it to es6 all my compiler errors disappear.

tsconfig:

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

Index.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>

Example error (there are many of these from library classes):

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

One of my requirments is to run this website in IE11, so I need es5.

Any help would be much appreciated.

KnowHoper
  • 4,352
  • 3
  • 39
  • 54
  • Why do you define a `files` block into your tsconfig.json file and what does it contain? Thanks! – Thierry Templier Apr 11 '16 at 09:02
  • They are paths to the files I want in the dist, as there are some files I want to omit for various reasons, specs etc. "files": [ "typings/browser.d.ts", "app/boot-main.ts", However, when I remove the files entry, i get the same behavior. I cannot compile the code to es5. I could perhapsi use a Babel transpiler in SystemJS? Thanks Thierry :) – KnowHoper Apr 11 '16 at 10:14

1 Answers1

2

If you are transpiling to ES5 you may need to set ///<reference path="node_modules/angular2/typings/browser.d.ts"/> in your main typescript file.

From: https://stackoverflow.com/a/35737470/3279156

Community
  • 1
  • 1
sreeramu
  • 1,213
  • 12
  • 19