talira

Node's require.resolve() algorithm as a library, async and sync

open sourceMITfree

resolve implements Node.js's require.resolve() algorithm so a tool can find the file a module id points to on behalf of another file, asynchronously or synchronously. Options set the base directory, file extensions, extra paths and package iteration, and it can resolve a package's exports field for a given Node.js version or for import as well as require.

Problems it solves

  • find which file a require() in another file would load
  • resolve module paths the way Node does from my build tool
  • resolve a package's exports field for a given Node.js version

Features

  • async and sync resolution like require.resolve()
  • custom base directory, extensions and paths
  • exports field resolution by Node.js version or category
  • require or import conditions

Alternatives

The same job

These do what resolve does.

  1. tsconfig-paths Make Node resolve the paths aliases in your tsconfig.json at run time

Compare resolve with the top 3