程序入口点
¥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
。¥The program was started with a command-line flag that forces the entry point to be loaded with ECMAScript module loader, such as
--import
or--experimental-default-type=module
. -
该文件的扩展名为
.mjs
。¥The file has an
.mjs
extension. -
该文件没有
.cjs
扩展名,并且最近的父package.json
文件包含值为"module"
的顶层"type"
字段。¥The file does not have a
.cjs
extension, and the nearest parentpackage.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.