__dirname is not defined in ES module scope
这是因为 package.json
{"type": "module"}
解决方法
import {dirname} from 'node:path' import {fileURLToPath} from "node:url"; globalThis.__filename = fileURLToPath(import.meta.url)//vite globalThis.__dirname = dirname(__filename)