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();
声明:本站所有文章和图片,如无特殊说明,均为原创发布。商业转载请联系作者获得授权,非商业转载请注明出处。
随机推荐
Express 使用 method-override 处理动词覆盖
Linux 中 top 命令的 Load Average 含义
如何使用命令修改 MySQL 数据库名称
WordPress 自定义模板路径
JavaScript 引用类型
Git push 错误:Updates were rejected because the remote contains work that you do not have locally
TypeScript 和 Koa 实践
JavaScript 的 this 指向