Cannot compile any TS+node.js project including listed in samples http://typescript.codeplex.com/sourcecontrol/latest#samples/imageboard/README.txt
Always get the following error:
error TS5037: Cannot compile external modules unless the '--module' flag is provided.
compiler's version: 0.9.1.0
For example, the project consists of just single file app.ts:
///<reference path="./node_definitions/node.d.ts" /
import http = require("http")
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, 'localhost');
console.log('Server running at http://localhost:1337/');
Also just to add.
I am using Visual Studio 2013 I got this same error running build to fix it. I went to the properties of my project and then to the "TypeScript Build" section in there was the option to pick a module system I selected AMD it was at none.
As mentioned compile with the module flag, e.g. if your file is called myfile.ts
:
tsc myfile.ts --module "commonjs"
The reason is that starting from TSC 0.9.1 the default module option is amd (e.g. requirejs) which is the most common module pattern for client side javascript code. So, you need to specify the module option to get commonjs code which is the most common module pattern for server side javascript code (e.g. nodejs) which is why the compiler is prompting you to be explicit about your target :) This prompt occurs when you do an import
on an external module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With