_dirname is not defined in ES module scope

原因是 ESM 中没有全局 __filename,重新定义下它:

import path from 'node:path'
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
posted @ 2024-03-17 22:24  guangzan  阅读(155)  评论(0编辑  收藏  举报