require.resolve(request[, options])


  • request <string> 要解析的模块路径。
  • options <Object>
    • paths <string[]> 用于解析模块位置的路径。如果存在,这些路径将替代默认解析路径使用,但像 $HOME/.node_modules 这样的路径始终会被包含。这些路径中的每一个都会被用作模块解析算法的起点,这意味着会从该位置开始检查 node_modules 层次结构。
  • 返回:<string>

使用内部的 require() 机制查找模块的位置,但不是加载模块,而是直接返回解析后的文件名。

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

如果找不到该模块,将抛出 MODULE_NOT_FOUND 错误。

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