美文网首页
__dirname is not defined in ES m

__dirname is not defined in ES m

作者: Amy_yqh | 来源:发表于2023-03-13 17:51 被阅读0次
    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