__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 ‘路径\package.json’ contains “type”: “module”. To treat it as a CommonJS script, rename it to use
the ‘.cjs’ file extension.

你看报错,上面写清楚了 package.json’ contains “type” 则以.js结尾的文件将被加载为ES模块

import path from "path"
const __dirname = path.resolve();

你可能感兴趣的:(javascript,node.js)