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 事件流
视频剪辑软件 Shotcut 笔记
WordPress 添加 Favicon 图标的方法
JavaScript 修改内容和属性
Express 使用 cookie-session 处理 session
JavaScript 代码混淆加密工具 javascript-obfuscator
WordPress 插件路径相关
JavaScript 滚动浏览器窗口到指定的元素