【问题标题】:Typescript not compiling打字稿不编译
【发布时间】:2013-08-19 22:00:45
【问题描述】:

我正在尝试在 Windows 上编译我的 trypescript 应用程序,使用

C:/nodejs/tsc.cmd --sourcemap app.ts --module

这是我得到的错误:

C:\nodejs\node_modules\typescript\bin\tsc.js:55708
                    type = type.toLowerCase();
                                ^
TypeError: Cannot call method 'toLowerCase' of undefined
    at Object.opts.option.set (C:\nodejs\node_modules\typescript\bin\tsc.js:55708:33)
    at OptionsParser.parse (C:\nodejs\node_modules\typescript\bin\tsc.js:55258:36)
    at BatchCompiler.parseOptions (C:\nodejs\node_modules\typescript\bin\tsc.js:55771:18)
    at BatchCompiler.batchCompile (C:\nodejs\node_modules\typescript\bin\tsc.js:55328:22)
    at Object.<anonymous> (C:\nodejs\node_modules\typescript\bin\tsc.js:56015:7)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

理想情况下,它表示 typescript 库本身存在问题,但这似乎不太可能。

我通过npm instal typescript 安装打字稿,我的版本是0.9.1,非常感谢任何帮助。

这是我正在尝试编译的打字稿代码:

///<reference path='node/node.d.ts' />
///<reference path='node/express.d.ts' />

import http = module("http")
import path = module("path")
import express = module("express")
import index = module("./routes/index")
import user = module("./routes/user")

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

app.get('/', index.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

【问题讨论】:

    标签: node.js typescript


    【解决方案1】:

    指定模块类型。由于它的节点 js 将是“commonjs”:

    C:/nodejs/tsc.cmd --sourcemap app.ts --module "commonjs" 
    

    更新:要修复 http not found 编译时错误,这里有一个快速的 typescript 定义:

    declare module "http"{
    }
    

    【讨论】:

    • 现在它给了我错误,说找不到文件“http”。
    • @GamesBrainiac 这是一个不同的问题,但更新了答案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 2021-07-01
    • 1970-01-01
    • 2017-06-26
    相关资源
    最近更新 更多