【问题标题】:Typescript compiler error: Cannot call method 'toLowerCase' of undefined打字稿编译器错误:无法调用未定义的方法“toLowerCase”
【发布时间】:2013-12-13 12:18:51
【问题描述】:

我正在将我的 NodeJs + ExpressJS 项目转换为 Typescript,我在控制台中看到了这个编译器错误。它甚至没有指向任何特定的代码段,这就是为什么我不知道从哪里开始诊断问题的原因。本项目使用 NodeJS + ExpressJS。我在 Webstorm 中对其进行编码,Typescript 的 Webstorm "FileWatcher" 会自动编译项目。

C:/Users/Me/AppData/Roaming/npm/tsc.cmd --sourcemap Main.d.ts --out main.js --module

C:\Users\Me\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:55958
                    type = type.toLowerCase();
                                ^
TypeError: Cannot call method 'toLowerCase' of undefined
    at Object.opts.option.set (C:\Users\Me\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:55958:33)
    at OptionsParser.parse (C:\Users\Me\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:55506:36)
    at BatchCompiler.parseOptions (C:\Users\Me\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:56054:18)
    at BatchCompiler.batchCompile (C:\Users\Me\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:55576:22)
    at Object.<anonymous> (C:\Users\Me\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:56298: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


【解决方案1】:

如果设置了模块标志,我们必须指定一个模块。因为它是一个 NodeJS 项目,所以模块是“commonjs”。编译器命令应该是

tsc.cmd --sourcemap Main.d.ts --out main.js --module "commonjs"

【讨论】:

    猜你喜欢
    • 2017-07-21
    • 2013-11-08
    • 2011-11-12
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多