require.resolve(request[, options])


  • request <string> 要解析的模块路径。
  • options <Object>
    • paths <string[]> 从中解析模块位置的路径。 如果存在,则使用这些路径而不是默认的解析路径,除了 GLOBAL_FOLDERS(例如 $HOME/.node_modules,其总是被包含在内)。 这些路径中的每一个都用作模块解析算法的起点,这意味着从此位置检查 node_modules 层级。
  • 返回: <string>

使用内部的 require() 工具查找模块的位置,但不加载模块,只返回解析的文件名。

如果找不到模块,则会抛出 MODULE_NOT_FOUND 错误。

  • request <string> The module path to resolve.
  • options <Object>
    • paths <string[]> Paths to resolve module location from. If present, these paths are used instead of the default resolution paths, with the exception of GLOBAL_FOLDERS like $HOME/.node_modules, which are always included. Each of these paths is used as a starting point for the module resolution algorithm, meaning that the node_modules hierarchy is checked from this location.
  • Returns: <string>

Use the internal require() machinery to look up the location of a module, but rather than loading the module, just return the resolved filename.

If the module can not be found, a MODULE_NOT_FOUND error is thrown.