程序入口点
程序入口点是类似说明符的字符串。 如果字符串不是绝对路径,则解析为当前工作目录的相对路径。 然后由 CommonJS 模块加载器解析该路径。 如果没有找到对应的文件,则抛出错误。
如果找到文件,则其路径将在以下任一条件下传给 ECMAScript 模块加载器:
- 该程序以命令行标志启动,该标志强制使用 ECMAScript 模块加载器加载入口点。
- 该文件的扩展名为
.mjs
。 - 该文件没有
.cjs
扩展名,并且最近的父package.json
文件包含值为"module"
的顶层"type"
字段。
否则,使用 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.
If a file is found, its path will be passed to the ECMAScript module loader under any of the following conditions:
- The program was started with a command-line flag that forces the entry point to be loaded with ECMAScript module loader.
- The file has an
.mjs
extension. - 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"
.
Otherwise, the file is loaded using the CommonJS module loader. See Modules loaders for more details.