【问题标题】:Unable to import in typescript file in nodejs无法在nodejs中导入打字稿文件
【发布时间】:2014-04-16 15:12:44
【问题描述】:

我正在尝试在 Typescript 文件中导入下划线模块,但这会造成麻烦,因为当我在节点中运行 typescript 模块时,它会引发错误:

Code:    
import _ = require('underscore');

Error:
import _ = require('underscore');
^^^^^^
SyntaxError: Unexpected reserved word
    at Module._compile (module.js:439:25)
    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)
    at require (module.js:380:17)

【问题讨论】:

    标签: node.js typescript


    【解决方案1】:

    您必须编译 TypeScript 文件。然后,在 node 中运行生成的 .js 文件。

    【讨论】:

    • 我在 Webstorm(我正在使用的 IDE)中有一个文件监视程序,它会自动执行此操作。还有其他可能吗?
    • WebStorm 无法正确编译文件,或者您在 .ts 而不是 .js 上运行节点
    猜你喜欢
    • 2017-02-28
    • 2022-01-20
    • 2021-08-14
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 2021-11-11
    相关资源
    最近更新 更多