I'm using angularjs and typescript to create some app, I'm having a trouble with this error that I can't solve
Here is my *.ts code
export var NgApp = new application.Startup();
///<reference path="../../../../../typings/tsd.d.ts"/>
import {NgApp} from "../../bootstrap";
module views.components.home {
export class HomeComponent {
public constructor() {
}
public static factory():Function[] {
return [
() => new HomeComponent()
]
}
}
}
NgApp.registerComponents(views.components.home,() => this.app.controller);
Here is my GULP task
let tsResult = gulp.src('src/**/*.ts').pipe(ts({
module: 'commonjs',
sourceMap: true
}));
let taskTs = tsResult.js.pipe(gulp.dest('built/'));
This is my error: Uncaught ReferenceError: exports is not defined
The question is: How can I use import like es6 in typescript? What I am missing?
click here "Solved finally" i was also getting same error i changed module:"commonjs" to "module": "es6", because targeting ES5 remove the import/export statements, so these tools cannot remove unused exports.
You need to use a module loader. Here is a sample that uses webpack : https://github.com/AngularClass/angular2-webpack-starter
I use angular 1.6 and webpack, it works on my side when i changed the module to "umd"
pasted here is my tsconfig.json after I changed it, I run $ tsc
then my "exports is not defined" error is gone.