For AI agents: the complete documentation index is available at https://rspack.rs/llms.txt, the full documentation bundle is available at https://rspack.rs/llms-full.txt, and this page is available as Markdown at https://rspack.rs/api/javascript-api/resolver.md.
close

Resolver API

Rspack uses the higher-performance rspack-resolver written in Rust to replace webpack's enhanced-resolve, and experimentally re-exports these APIs through rspack.experiments.resolver. This allows you to directly call rspack-resolver's functions like resolver.sync or resolver.async.

For complete usage and options, see rspack-resolver. Below is a simple example demonstrating how to use Rspack to resolve module paths:

import { rspack } from '@rspack/core';

const { resolver } = rspack.experiments;

// Directly use Resolver API with default options
const { path: syncResolvedPath } = resolver.sync(contextPath, './index.js');
const { path: asyncResolvedPath } = await resolver.async(
  contextPath,
  './index.js',
);

// Use ResolverFactory with custom options
const customResolver = new resolver.ResolverFactory(resolveOptions);
const syncResult = customResolver.sync(contextPath, './request.js');
const asyncResult = await customResolver.async(contextPath, './request.js');