esm-resolve is a synchronous ESM import resolver for Node.js, designed to be used within development servers or build processes. Currently at version 1.0.11, it offers a stable and permissive approach to module resolution. Key differentiators include its pure JavaScript implementation, support for modern Node.js resolution features like subpath exports/imports and conditional exports, and a default behavior that rewrites to 'browser', 'import', or 'default' keys (rather than 'node'). It was developed before `import.meta.resolve()` was widely available and aims to provide a more permissive resolution experience. The library is designed to fail gracefully and also handles the removal of imports pointing purely to `.d.ts` files, simplifying TypeScript workflows. While it doesn't specify a strict release cadence, its 1.x versioning suggests a mature and stable library.
npm install esm-resolveVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `esm-resolve` with `buildResolver`, perform basic relative and package resolutions, and configure the resolver for Node.js-specific behaviors and `.mjs` file matching using options like `constraints` and `matchNakedMjs`.
Evaluate if native `import.meta.resolve()` (now synchronous in Node.js v20+) meets your needs, or if `esm-resolve`'s permissive and configurable features are required for your specific build or dev server scenario.
If resolving for a Node.js environment, explicitly set the `constraints` option to `'node'` when calling `buildResolver`: `buildResolver(importer, { constraints: 'node' })`.To always receive an absolute path, set the `resolveToAbsolute` option to `true`: `buildResolver(importer, { resolveToAbsolute: true })`.Be aware of this behavior and thoroughly test your import resolutions, especially in production builds, to ensure that the permissive resolution doesn't hide misconfigurations that could cause problems in different environments or with other tools.
If you are resolving in a Node.js environment, ensure you pass `{ constraints: 'node' }` to `buildResolver` to correctly match Node.js-specific `exports` conditions in `package.json`. Also, verify file extensions and subpath exports.Ensure you are using ESM `import` statements: `import buildResolver from 'esm-resolve';` or `import { buildResolver } from 'esm-resolve';`. If your project uses CommonJS, you may need to configure your build system to handle ESM dependencies or reconsider the library choice.No dependency data recorded yet.