【问题标题】:TSC cannot find name of Global ObjectTSC 找不到全局对象的名称
【发布时间】:2018-01-08 19:14:45
【问题描述】:

在我的打字稿代码中,我试图访问 __dirname 全局对象:https://nodejs.org/docs/latest/api/globals.html

我看到一个编译错误:TS2304:Cannot find name '__dirname'. 我可以毫无问题地运行代码。怎样才能让tsc编译不出错?

【问题讨论】:

    标签: node.js typescript


    【解决方案1】:

    tsconfig.json 中添加"node"compilerOptions.types

    例子:

    {
     "compilerOptions": {
      ...
      "types": [
        "node"
      ]
      ...
      }
    }
    

    然后运行npm install @types/node --save-dev

    【讨论】:

      猜你喜欢
      • 2019-12-28
      • 1970-01-01
      • 2016-04-25
      • 2016-12-21
      • 2018-05-16
      • 2017-09-07
      • 1970-01-01
      • 2018-11-16
      • 1970-01-01
      相关资源
      最近更新 更多