I want to use Angular 2 with TypeScript and compile to JavaScript using gulp-typescript
.
But I got error Cannot find module 'angular2/angular2'.
.
Then, I tried to change code like the following.
Code
/// <reference path="../../../node_modules/angular2/core.d.ts" />
import {bootstrap, Component} from 'angular2/angular2';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
class AppComponent { }
bootstrap(AppComponent);
I got below stacktrace
app/assets/scripts/application.ts(2,36): error TS2307: Cannot find module 'angular2/angular2'.
/Users/xxxx/app/node_modules/angular2/src/core/application_ref.d.ts(83,60): error TS2304: Cannot find name 'Promise'.
/Users/xxxx/app/node_modules/angular2/src/core/application_ref.d.ts(83,146): error TS2304: Cannot find name 'Promise'.
/Users/xxxx/app/node_modules/angular2/src/core/application_ref.d.ts(96,51): error TS2304: Cannot find name 'Promise'.
/Users/xxxx/app/node_modules/angular2/src/core/application_ref.d.ts(96,147): error TS2304: Cannot find name 'Promise'.
/Users/xxxx/app/node_modules/angular2/src/core/application_ref.d.ts(133,90): error TS2304: Cannot find name 'Promise'.
/Users/xxxx/app/node_modules/angular2/src/core/application_ref.d.ts(171,81): error TS2304: Cannot find name 'Promise'.
The following are configuration for gulp-typescript and typings (instead of tsd), tsconfig.
// gulpfile.js
...
gulp.task('ts', function() {
var tsconfig = require('./tsconfig.json');
gulp
.src(path.ts)
.pipe($.typescript(tsconfig.compilerOptions))
.pipe($.concat('application.js'))
.pipe(gulp.dest('dist/assets/'));
});
...
// typings.json
{
"dependencies": {},
"devDependencies": {},
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
}
}
// tsconfig.json
{
"compilerOptions": {
"target" : "es5",
"module" : "commonjs",
"sourceMap" : false,
"emitDecoratorMetadata" : true,
"experimentalDecorators": true,
"removeComments" : false,
"noImplicitAny" : false
},
"exclude": [
"node_modules"
]
}
How to compile TypeScript using gulp-typescript in order to use Angular 2?