3
votes

I would appreciate if somebody could give some light on TypeScript 1.8 modules.

I have SomeClass.ts file:

export class SomeClass {

}

and then, in my app.ts I import SomeClass:

import {SomeClass} from "./SomeClass";
var xxx = new SomeClass();

Both with AMD and CommonJS module system, ES5 target, I build the app and if I open it in browser I get either "define is not defined" or "require is not defined" error.

Should I install some additional libraries for this to work?

2
it should work if you target es5 commonjs. - AlexG
you need to actually load the library script in your page - Nitzan Tomer

2 Answers

4
votes

Set the module system to "amd". Download requirejs and include it in your HTML.

<script data-main="scripts/app" src="scripts/require.js"></script>

Notice the data-main attribute. Its value is the path + module name, in your case "app". Requirejs will fetch your module, so you shouldn't include it in another script tag.

1
votes

Should I install some additional libraries for this to work?

Yes. However you can easily bundle the library in along with your project. E.g. use commonjs (allows you to use npm flawlessly) and then compile with webpack.

More

Quickstart : https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html