程序入口点


¥Program entry point

程序入口点是类似说明符的字符串。如果字符串不是绝对路径,则解析为当前工作目录的相对路径。该路径然后由 CommonJS 模块加载器解析。如果没有找到对应的文件,则抛出错误。

¥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. 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)加载入口点。

    ¥The program was started with a command-line flag that forces the entry point to be loaded with ECMAScript module loader, such as --import.

  • 该文件的扩展名为 .mjs

    ¥The file has an .mjs extension.

  • 该文件没有 .cjs 扩展名,并且最近的父 package.json 文件包含值为 "module" 的顶层 "type" 字段。

    ¥The file does not have a .cjs extension, and the nearest parent package.json file contains a top-level "type" field with a value of "module".

否则,使用 CommonJS 模块加载器加载文件。有关详细信息,请参阅 模块加载器

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