一、node版本低于20.11.0 import * as url from 'url'; const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); const __filename = url.fileURLToPath(import.meta.url); 二、node版本高于20.11.0 import.meta.dirname // 当前模块所在的目录 import.meta.filename// 当前模块文件名