【发布时间】:2013-08-25 01:39:33
【问题描述】:
我正在尝试让它工作,但我似乎无法在 SO 上的任何地方找到解决方案。尝试编译此单文件应用程序时:
import http = require('http')
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
使用命令“tsc app.ts --module 'commonjs'”我得到以下错误(不使用 --module 标志会给我一个额外的错误,告诉我我需要它来编译外部模块):
error TS2071: Unable to resolve external module '"http"'.
error TS2072: Module cannot be aliased to a non-module type.
【问题讨论】:
-
尝试
var而不是import。var http = require('http') -
给我
error TS2095: Could not find symbol 'require'.。我见过的所有示例都使用import声明。 -
如果您使用 var,您的导入将无法正确输入。
-
@Shoerob 您能否详细说明您的评论。你的意思是如果我们使用 'var' 而不是 'import',intelliSense 就不能工作了吗?
标签: node.js typescript