Script served by Typescript and ExpressJs is not run

I would like to translate my minimalistic server from Coffeescript to Typescript. Here's the original code:

express = require("express")
app=express()
app.use(express.static(__dirname))
app.set("views", __dirname + "/views")
app.set("view engine", "jade")
app.get("/", (req,res)->
        res.render "index")
port = process.env.PORT or 5000
server=app.listen(port)

io=require("socket.io").listen(server)
io.sockets.on("connection", (socket)->socket.emit("news", "data"))

and here's the Typescript version:

/// <reference path="d.ts/node.d.ts"/>
/// <reference path="d.ts/socket.io.d.ts"/>
/// <reference path="d.ts/express3.d.ts"/>

import express3 = module("express3");
var express = require("express");
var app = express();
app.use(express.static(__dirname));
app.set("views", __dirname+"/views");
app.set("view engine", "jade");

app.get("/", (req, res) => { res.render("index"); });

var port = 5000;
var server=app.listen(port);

import socketio = module("socket.io");
var io=socketio.listen(app);
io.sockets.on("connection", (socket) => { socket.emit("news", "data"); });

Both versions compile to server.js without problems. The generated code has a different style but as far as I can see, the semantics should be the same. You can take a look at the two output files on pastebin.

coffeescript: http://pastebin.com/38LZhcPZ

typescript: http://pastebin.com/95ABVsB2

The response "index.jade" contains a small unfinished game with RaphaelJs. Now here's the problem. If I start the coffeescript generated server.js and open localhost:5000, everything's fine. The game starts running.

But if I run the compiled typescript version, the game is not started. There's no problem with opening localhost:5000. The website is served without errors and if I inspect the page source, it's all there. At first I thought maybe the static file server of express would somehow not work. But when I click on <script src="../scripts/game.js"/> in the page source, the code is there. The game logic is started with window.onload, maybe there's a problem, but that would seem rather strange.

What can I do ?

At quick glance it doesn't seem to be the same code:

Original and CoffeeScript Generated:

io = require("socket.io").listen(server);

But your TypeScript code has:

var io = socketio.listen(app);

If you modify your TypeScript code to the following I think you should be in action:

var io = socketio.listen(server);

Your call to socketio.listen() is passing app in the CoffeeScript example but server in the TypeScript example.

var io = socketio.listen(app);

io = require("socket.io").listen(server);