Error "Define is not defined"

Topics: General
Feb 17, 2014 at 10:42 AM
Edited Feb 17, 2014 at 10:43 AM
Hi
I created a GameModule.ts with the following code:

export module Game1 {
export class Game2{
    constructor(){
        this.draw();
    }

    public draw() {
        console.log("test");
    }
}
}

and inside the app.ts I call this module like following:

/// <reference path="GameModule.ts" />
import GameModule = require("GameModule");


var g = new GameModule.Game1.Game2();

code compiles without any error, but it will throw exception in browser with following details:

"ReferenceError: define is not defined"

I'm using Visual Studio 2013 Ultimate, Typescript version 0.9.5 and Web Essentials 2013 version 1.8.5.

Any help is really appreciated.
Regards.
Feb 17, 2014 at 2:22 PM
If you're going to use import you will need an AMD loader.

If you're going to include the script in the browser yourself then simply drop the import statement.
You'll also need to remove the export from module Game1.

Basically you need to understand how internal and external modules work.

Here is a short and sweet introduction that I found: http://blog.oio.de/2014/01/31/an-introduction-to-typescript-module-system/
Feb 18, 2014 at 4:51 PM
Hi nabog

Thank you for your reply.
As you said I removed export from module Game1 and dropped the import statement but now at the run time I catch the following error:

"ReferenceError: Game1 is not defined".

Here is the code of "Game1.ts".
module Game1 {
export class Game2 {
    constructor() {
        this.draw();
    }

    public draw() {
        console.log("test");
    }
}
}

And here is the code of "app.ts":

/// <reference path="Game1.ts" />
window.onload = () => {
 var g = new Game1.Game2();
g.draw();

Both type script files are located at the root of the project. I don't now what is wrong with it. Am I miss anything else????
};
Coordinator
Feb 18, 2014 at 5:14 PM
Your HTML page needs to actually load both .js files through script tags; simply having the script files in the project will not cause them to be loaded in the browser.