Marko
Marko

Reputation: 10992

How to compile Typescript with Angular 2?

I get the following errors:

Error:(7, 5) TS1148: Cannot compile modules unless the '--module' flag is provided.
Error:(7, 40) TS2307: Cannot find module 'angular2/angular2'.
Error:(8, 5) TS1205: Decorators are only available when targeting ECMAScript 5 and higher.
Error:(12, 11) TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.

Not sure what to do. I've trying out the quickstart tutorial on Angular site, below is my code. I think something needs to be done in conjuction with typescript, but what?

app.ts

import {Component, bootstrap} from 'angular2/angular2';
@Component({
    selector: 'my-app',
    template: '<h1>My First Angular 2 App</h1> <p>hello</p>'
})
class AppComponent { }

bootstrap(AppComponent);

index.html

<html>
  <head>
    <title>Angular 2 QuickStart</title>
    <script src="https://code.angularjs.org/tools/system.js"></script>
    <script src="https://code.angularjs.org/tools/typescript.js"></script>
    <script src="https://code.angularjs.org/2.0.0-alpha.44/angular2.dev.js"></script>
    <script>
      System.config({
        transpiler: 'typescript',
        typescriptOptions: { emitDecoratorMetadata: true }
      });
      System.import('./app.ts');
    </script>
  </head>
  <body>
    <my-app>loading...</my-app>
  </body>
</html>

Upvotes: 0

Views: 505

Answers (1)

Luca
Luca

Reputation: 4273

I think you need tsconfig.json file. Here a sample content:

 {
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  }
}

Upvotes: 1

Related Questions