ReferenceError: __dirname is not defined in ES module scope

ReferenceError: __dirname is not defined in ES module scope

This file is being treated as an ES module because it has a '.js' file extension and '/Users/ice/www/next/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.


解决办法:

import path from "path";
const __dirname = path.resolve();
声明:本站所有文章和图片,如无特殊说明,均为原创发布。商业转载请联系作者获得授权,非商业转载请注明出处。
随机推荐
JavaScript ES6 模块
WordPress 函数 add_option()、get_option() 和 update_option()
JavaScript 滚动浏览器窗口到指定的元素
WordPress 文章排序
PHP curl 的用法
JavaScript 窗口/文档事件
MySQL 数据库中货币单位如何存储
HTML input datetime 日期时间选择器