在我的typescript代码中,我尝试访问__dirname
全局对象:https://nodejs.org/docs/latest/api/globals.html
我看到一个编译错误:TS2304:Cannot find name '__dirname'.
我可以毫无问题地运行代码。怎样才能让tsc
不出错地进行编译?
发布于 2017-08-01 19:46:11
在tsconfig.json
中,将"node"
添加到compilerOptions.types
。
示例:
{
"compilerOptions": {
...
"types": [
"node"
]
...
}
}
然后运行npm install @types/node --save-dev
https://stackoverflow.com/questions/45445976
复制相似问题