程序入口点
【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。 - 该文件具有
.mjs或.wasm扩展名。 - 该文件没有
.cjs扩展名,并且最近的父级package.json文件包含一个顶层"type"字段,其值为 "module"。
否则,文件将使用 CommonJS 模块加载器加载。更多详情请参阅 模块加载器。
【Otherwise, the file is loaded using the CommonJS module loader. See Modules loaders for more details.】