AngularJs 2 failed to boot when generate all typescript file output to single js file

282 Views Asked by At

I am using angular 2 with typescript (V-1.8) in my project. I have configured my tsconfig to generate output into single .js file. This file also have code to bootstrap application as boot.ts file also get transpiled in .js file. My application structure is as below.

Root
|_app
|   |  |__Module1
|   |    |_a.ts
|   |    |_b.ts
|   |__Module2
|   |___|_xyz.ts
|   |
|   |_Boot.ts
|_Js
| |_Deployment
|            |_single.js
|_index.html
|_package.json
|_tsconfig.json

In index.html I have added

<script type="text/javascript" src="js/Deployment/single.js"></script>
  <!-- 2. Configure SystemJS -->
  <script>
   System.config({
      packages: {
        app: {
          format: 'register',
          defaultExtension: 'js'
        }
      }
    });

    System.import('js/Deployment/single').then(null, console.error.bind(console));
  </script>

In code generated inside single.js looks fine. In node command prompt I seen error as in below image.

Ts error 2661

Hence application is fail to load. I am not getting any clue whether this is angular 2 error, syntax error or anything else. If I generate separate .js file per .ts file and modify index.html as

<script>
   System.config({
      packages: {
        app: {
          format: 'register',
          defaultExtension: 'js'
        }
      }
    });

    System.import('app/boot').then(null, console.error.bind(console));
  </script>

application works fine. Please help me to understand what goes wrong in single.js case.

Thanks in advance.

1

There are 1 best solutions below

3
On

Check this github thread: https://github.com/angular/angular/issues/6468

For your convinience, user sicaner suggests:

I solve this problem by adding declare var Promise: PromiseConstructor; on the top of promise.d.ts

Since this issue was closed, before modifying promise.d.ts you may try to update angular version - maybe fix will be already there.