Reputation: 2327
I am making a NodeJs console application with NodeJS Tools for Visual Studio (http://nodejstools.codeplex.com/) with the Typescript template.
Here is basicaly my code :
app.ts :
/// <reference path="Module/Module.ts" />
var foo = new Module.ModuleClass();
foo.foo();
Module/Module.ts :
module Module {
export class ModuleClass {
foo() {
console.log('Hello World');
}
}
}
The compiler run without trouble but on runtime, NodeJS can't find the module. Here is the error :
var foo = new Module.ModuleClass();
^
ReferenceError : Module is not defined
I tired a lot of thing about that problem (using or not the /// but I can't find any solution.
Excuse me for my English, I am not a native speaker. Thanks in advance !
Upvotes: 3
Views: 7301
Reputation: 2400
You need to export Module
in Module/Module.ts
export module Module { ...
In app.ts, you need to require('./Module/Module')
import M = require('./Module/Module');
var foo = new M.Module.ModuleClass();
foo.foo();
You need to do this because this node.js uses the commonjs module system, which typescript supports via its "external" modules feature and a compiler arg --module commonjs
Upvotes: 4