typescript报错Cannot find name ‘__dirname‘

  1. vite.config.ts中报错 Cannot find name ‘__dirname’

  2. 解决方案

  • 将 “node” 添加到 tsconfig.json 文件中 compilerOptions.types
{
    
    
 "compilerOptions": {
    
    
  ...
  "types": [
    "node"
  ]
  ...
  }
}
  • 安装@types/node
npm install @types/node --save-dev

猜你喜欢

转载自blog.csdn.net/qq_41839808/article/details/124706746