程序入口点


¥Program entry point

程序入口点是类似说明符的字符串。如果字符串不是绝对路径,则解析为当前工作目录的相对路径。然后,该入口点字符串将被解析,就好像它是 require() 从当前工作目录请求的一样。如果没有找到对应的文件,则抛出错误。

¥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 entry point string is then resolved as if it's been requested by require() from the current working directory. If no corresponding file is found, an error is thrown.

默认情况下,解析后的路径也会像 require() 请求的那样加载,除非满足以下条件之一 - 在这种情况下,它会像 import() 请求的那样加载:

¥By default, the resolved path is also loaded as if it's been requested by require(), unless one of the conditions below apply—then it's loaded as if it's been requested by import():

  • 程序以命令行标志启动,该标志强制使用 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.mts.wasm

    ¥The file has an .mjs, .mts or .wasm 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".

有关详细信息,请参阅 模块解析和加载

¥See module resolution and loading for more details.