Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find external module 'angular2/angular2' - Angular2 w/ Typescript

I am going through the step by step tutorial on angular.io (Angular 2). I am using typescript. I get the following error when trying to compile:

Cannot find external module 'angular2/angular2'

using the watch command.

main.ts

import {Component, View, bootstrap} from 'angular2/angular2';

@Component({
  selector: 'my-app'
})

@View({
  template: '<h1>My first Angular 2 App</h1>'
})

class AppComponent {
}

bootstrap(AppComponent);

index.html

<!DOCTYPE html>
<html>
  <head>
    <script src="https://jspm.io/[email protected]"></script>
    <script src="https://code.angularjs.org/2.0.0-alpha.23/angular2.dev.js"></script>
  </head>
  <body>

    <my-app></my-app>

    <script>
      System.import('main');    
    </script>

  </body>
</html>

Q Why is this error occuring?

like image 404
karns Avatar asked Jun 16 '15 03:06

karns


2 Answers

Adding these files to the head will give you the latest working version of Angular2.

<script src="https://github.jspm.io/jmcriffey/[email protected]/traceur-runtime.js"></script>
<script src="https://jspm.io/[email protected]"></script>
<script src="https://code.angularjs.org/2.0.0-alpha.26/angular2.dev.js"></script>

Source: Angular.io: 5 Minute Quickstart

like image 69
shmck Avatar answered Oct 31 '22 02:10

shmck


The TypeScript Definition (TSD) for Angular2 is missing:

 - cd src               //go to the directory where your ts-file is
 - tsd install angular2 //load Angular2 TypeScript Definition

Then compile again (e.g. tsc -p src -w)

If tsd fails install it first:

npm install -g tsd@^0.6.0
like image 34
Dunken Avatar answered Oct 31 '22 02:10

Dunken