在nodejs中使用es module时,__dirname未定义,因为__dirname、__filename只有在commonjs 中才有;
报错: __dirname is not defined in ES module scope
解决方式:
import { dirname } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))