TSC cannot find name of Global Object

前端 未结 1 1719
野性不改
野性不改 2021-02-13 22:23

In my typescript code I am trying to access the __dirname global object: https://nodejs.org/docs/latest/api/globals.html

I am seeing a compile error:

1条回答
  •  有刺的猬
    2021-02-13 22:47

    In tsconfig.json add "node" to compilerOptions.types.

    Example:

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

    Then run npm install @types/node --save-dev

    0 讨论(0)
提交回复
热议问题