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: TS2304:Cannot find name '__dirname'.
I can run the code without any issue. How can I get tsc
to compile without error?
In tsconfig.json
add "node"
to compilerOptions.types
.
Example:
{
"compilerOptions": {
...
"types": [
"node"
]
...
}
}
Then run npm install @types/node --save-dev