> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Module resolution

Module resolution is the process of converting a module identifier to a module's file path.

Rspack uses [rspack-resolver](https://github.com/rstackjs/rspack-resolver) for module path resolution, which is an extension to the [Node.js module resolution algorithm](https://nodejs.org/api/esm.html#resolution-algorithm-specification) with the same interface as [enhanced-resolve](https://github.com/webpack/enhanced-resolve).

Refer to [resolve configuration](/config/resolve.md) for more information about module resolution configuration.

## Rspack

Rspack supports the following three kinds of file paths:

### Absolute paths

```js
import '/home/me/file';
```

Since this path is already an absolute path, there is usually no need to do further parsing, just return the path directly.

### Relative paths

```js
import './src/answer';
```

In this case, the directory where the resource files using import and require are located is considered the context directory. The relative path given in import/require is spelled out with that context directory path to generate the absolute path to the module.

### Module paths

```js
import 'lodash';
```

Module paths are those that do not start with `'./'`, `'../'`, `'/'`. In this case, Rspack will resolve the absolute path of the module according to the module resolution rules. The [node module resolution algorithm](https://nodejs.org/api/modules.html#modules_all_together) has a detailed description of the rules for resolve modules.

## package.json `imports`

Rspack's resolver supports the [imports](https://nodejs.org/api/packages.html#subpath-imports) field in `package.json` for resolving module identifiers that start with `#` within a package.

In the following example, both `#utils` and `#/main` are resolved from the current package's `imports` field:

```json title="package.json"
{
  "imports": {
    "#utils": "./src/utils/index.js",
    "#/*": "./src/*"
  }
}
```

```js title="src/index.js"
import utils from '#utils'; // resolves to ./src/utils/index.js
import main from '#/main.ts'; // resolves to ./src/main.ts
```

> Use the [`resolve.importsFields`](/config/resolve.md#resolveimportsfields) option to customize the field name used for `imports`.
