__dirname is not defined in ES m
作者:
Amy_yqh | 来源:发表于
2023-03-13 17:51 被阅读0次
![](https://img.haomeiwen.com/i7096759/f4f4bdbc8bd550ab.png)
image.png
// 解决__dirname不能使用问题
// 最新 node 核心包的导入写法
import { fileURLToPath } from 'node:url'
import { dirname } from 'node:path'
// 获取 __filename 的 ESM 写法
const __filename = fileURLToPath(import.meta.url)
// 获取 __dirname 的 ESM 写法
const __dirname = dirname(fileURLToPath(import.meta.url))
const getPath = _path =>path.resolve(__dirname,_path)
本文标题:__dirname is not defined in ES m
本文链接:https://www.haomeiwen.com/subject/hiicrdtx.html
网友评论