程序入口点


🌐 Program entry point

程序的入口点是类似于说明符的字符串。如果该字符串不是绝对路径,它将作为相对于当前工作目录的路径进行解析。然后,该路径由 CommonJS 模块加载器解析,或者如果传递了 --experimental-default-type=module,则由 ES 模块加载器 解析。如果找不到相应的文件,将抛出错误。

🌐 The program entry point is a specifier-like string. If the string is not an absolute path, it's resolved as a relative path from the current working directory. That path is then resolved by CommonJS module loader, or by the ES module loader if --experimental-default-type=module is passed. If no corresponding file is found, an error is thrown.

如果找到文件,其路径将在以下任何情况下传递给 ES 模块加载器

🌐 If a file is found, its path will be passed to the ES module loader under any of the following conditions:

  • 该程序是通过命令行标志启动的,该标志会强制入口点使用 ECMAScript 模块加载器加载,例如 --import--experimental-default-type=module
  • 该文件有一个 .mjs 扩展名。
  • 该文件没有 .cjs 扩展名,并且最近的父级 package.json 文件包含一个顶层 "type" 字段,其值为 "module"。

否则,文件将使用 CommonJS 模块加载器加载。更多详情请参阅 模块加载器

🌐 Otherwise, the file is loaded using the CommonJS module loader. See Modules loaders for more details.