我使用的是Node.js 10.0.0 &我的index.mjs如下所示:
import path from "path";
console.log(__dirname);在我的终点站,我跑
node --experimental-modules index.mjs我得到了以下错误:
(node:3750) ExperimentalWarning: The ESM module loader is experimental.
ReferenceError: __dirname is not defined
at file:///MyFolderPath/node-10/index.mjs:3:21
at ModuleJob.run (internal/modules/esm/module_job.js:106:14)发布于 2018-05-10 08:27:57
ESM不是特定于节点的,并且特定于节点的“全局”(如__dirname和模块)将无法工作。预计import.meta将提供合适的替代品。
资料来源: GitHub 问题.
https://stackoverflow.com/questions/50268077
复制相似问题