解析器算法
¥Resolver algorithm
加载 ES 模块说明符的算法通过下面的 ESM_RESOLVE 方法给出。它返回相对于 parentURL 的模块说明符的解析 URL。
¥The algorithm to load an ES module specifier is given through the ESM_RESOLVE method below. It returns the resolved URL for a module specifier relative to a parentURL.
确定已解析 URL 的模块格式的算法由 ESM_FORMAT 提供,它返回任何文件的唯一模块格式。"module" 格式为 ECMAScript 模块返回,而 "commonjs" 格式用于指示通过旧版 CommonJS 加载器加载。可以在未来的更新中扩展其他格式,例如 "addon"。
¥The algorithm to determine the module format of a resolved URL is provided by ESM_FORMAT, which returns the unique module format for any file. The "module" format is returned for an ECMAScript Module, while the "commonjs" format is used to indicate loading through the legacy CommonJS loader. Additional formats such as "addon" can be extended in future updates.
在以下算法中,除非另有说明,否则所有子程序错误都将作为这些顶层程序的错误传播。
¥In the following algorithms, all subroutine errors are propagated as errors of these top-level routines unless stated otherwise.
defaultConditions 是条件环境名称数组,["node", "import"]
。
¥defaultConditions is the conditional environment name array,
["node", "import"]
.
解析器可能会抛出以下错误:
¥The resolver can throw the following errors:
-
无效的模块说明符:模块说明符是无效的 URL、包名称或包的子路径说明符。
¥Invalid Module Specifier: Module specifier is an invalid URL, package name or package subpath specifier.
-
无效的包配置:package.json 配置无效或包含无效配置。
¥Invalid Package Configuration: package.json configuration is invalid or contains an invalid configuration.
-
无效的包目标:包导出或导入为包定义了一个目标模块,该模块是无效类型或字符串目标。
¥Invalid Package Target: Package exports or imports define a target module for the package that is an invalid type or string target.
-
未导出的包路径:包导出不为给定模块定义或允许包中的目标子路径。
¥Package Path Not Exported: Package exports do not define or permit a target subpath in the package for the given module.
-
包导入未定义:包导入不定义说明符。
¥Package Import Not Defined: Package imports do not define the specifier.
-
未找到模块:请求的包或模块不存在。
¥Module Not Found: The package or module requested does not exist.
-
不支持的目录导入:解析的路径对应于一个目录,该目录不是模块导入的受支持目标。
¥Unsupported Directory Import: The resolved path corresponds to a directory, which is not a supported target for module imports.