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();
声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。
随机推荐
CSS 图片缩小出现锯齿
WordPress 自定义模板路径
Three.js导入3D模型
JavaScript 触摸事件
FormData 对象
JavaScript 类
Express.js CSRF 安全防护
Node.js test 模块