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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With