TypeScript + Node.js FileSystem issue

1.8k views Asked by At

I have a simple typescipt program

/// <reference path="node-definitions/node.d.ts" />
import fs = require('fs');
fs.writeFileSync("test.txt","HelloWorld");

when I run it, it says that fs is empty https://www.dropbox.com/s/ygvfi8us4mdignd/Screenshot%202015-06-11%2010.11.12.png?dl=0

the generated js code is correct https://www.dropbox.com/s/egl06maalnsd04e/Screenshot%202015-06-11%2010.21.24.png?dl=0

if I require other modules, for instance require(“path”) all is ok but require(“fs”) always returns empty Object as I see they are declared inside node.d.ts in the same way (“path” and “fs” modules) also I have tried different versions of node.d.ts and node.js (0.10 - 0.12) Maybe someone know how to solve this issue?

1

There are 1 answers

0
basarat On

For nodejs compile your typescript with commonjs module format i.e.

tsc App.ts --module commonjs