CC 4.0 License
The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.
The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.
Resolve
Used to configure the Rspack module resolution logic.
- Type:
Object
resolve.alias
- Type:
Record<string, false | string | (string | false)[]> - Default:
{}
Path alias, e.g.
At this point:
require("@/a")will attempt to resolve<root>/src/a.require("abc")will attempt to resolve<root>/src/abc.require("abc/file.js")will not match, and it will attempt to resolvenode_modules/abc/file.js.
Impact on package resolution
When you use resolve.alias to redirect a package import (for example, import 'lib') to a specific directory inside a monorepo or within node_modules, the module resolution behavior changes:
- Default behavior: If the import is a package name, Rspack performs the full package resolution process: it reads the package's
package.jsonand determines the entry file and subpath mappings according to theexportsfield. - When aliased: When an alias resolves to a file system path — for example,
./node_modules/lib— Rspack no longer treats it as a package name and resolves it as a regular path. This bypasses the standard package resolution logic, causing fields such asexportsinpackage.jsonto no longer take effect. This is the intended and standard behavior of Node.js.
Monorepo usage
If you want packages within a monorepo to retain the same resolution behavior as regular npm packages, avoid using alias to point a package name directly to its source directory.
The recommended approach is to use your package manager's workspace feature to symlink sub-packages into node_modules, so they can be resolved just like normal dependencies.
resolve.aliasFields
- Type:
string[] - Default:
['browser']
Define a field, such as browser, that should be parsed in accordance with this specification.
resolve.conditionNames
- Type:
string[]
Specifies the condition names used to match entry points in the exports field of a package.
Default value
Rspack's default conditionNames are determined by mode, target and module type.
In the above example:
modeis determined by mode config, which isdevelopmentin development mode andproductionin other modes.targetis determined by target config:- If
targetincludesweb, it will bebrowser. - If
targetincludesnode, it will benode. - If
targetincludeswebworker, it will beworker. - If
targetincludeselectron, it will beelectron. - If
targetincludesnwjs, it will benwjs.
- If
Example
Rspack will match export conditions that are listed within the resolve.conditionNames array.
Note that the key order in the exports object determines priority. During condition matching, earlier entries have higher priority than later entries.
For example:
Importing:
'foo'will resolve to'foo/index-require.js''foo/bar'will resolve to'foo/bar-node.js'as the"node"key comes before"require"key in the conditional exports object.'foo/baz'will resolve to'foo/baz-node.js'
Extend default value
If you want to add your custom conditions names while still retaining the default Rspack values, you can use "...":
Alternatively, to prioritize the default value first and then add your custom condition names:
resolve.descriptionFiles
- Type:
string[] - Default:
['package.json']
The JSON files to use for descriptions.
resolve.enforceExtension
- Type:
boolean
By default, It changes to true if resolve.extensions contains an empty string; otherwise, this value changes to false.
If true, it will not allow extension-less files. So by default require('./foo') works if ./foo has a .js extension, but with this enabled only require('./foo.js') will work.
resolve.exportsFields
- Type:
string[] - Default:
["exports"]
Customize the exports field in package.json. e.g.
When this configuration is ["testExports", "exports"], the result of import value from 'lib' is lib/test.js.
resolve.extensions
- Type:
string[] - Default:
[".js", ".json", ".wasm"]
Automatically resolve file extensions when importing modules. This means you can import files without explicitly writing their extensions.
For example, if importing ./index, Rspack will try to resolve using the following order:
./index.js./index.json./index.wasm
Example
Here's how to configure custom extensions including TypeScript and JSX files:
When multiple files with the same name but different extensions exist, Rspack will resolve the file with the extension that appears first in the array.
For example, if both index.js and index.ts exist in the same directory, and your configuration is ['.ts', '.js'], then import './index' will resolve to index.ts.
Extend default value
Note that configuring resolve.extensions will completely override the default array, which means Rspack will no longer attempt to resolve modules using the default extensions.
To include the default extensions alongside your custom ones, you can use the spread syntax '...':
Performance considerations
- Avoid adding too many extensions as each one adds overhead to the resolution process. Keep the
extensionsarray as short as possible to improve resolution performance. - Place the most commonly used extensions first in the array.
resolve.extensionAlias
- Type:
Record<string, string[] | string> - Default:
{}
Define alias for the extension. e.g.
This is particularly useful for TypeScript projects, as TypeScript recommends using the .js extension to reference TypeScript files.
Rspack will try to resolve './foo.ts' and ./foo.js' sequentially when resolving import './foo.js'.
resolve.fallback
- Type:
Record<string, false | string> - Default:
{}
Redirect module requests when normal resolving fails.
Rspack does not polyfills Node.js core modules automatically which means if you use them in your code running in browsers or alike, you will have to install compatible modules from NPM and include them yourself.
You could use node-polyfill-webpack-plugin to polyfill Node.js core API automatically.
Or refer to the list of Node.js polyfills used by webpack 4:
resolve.importsFields
- Type:
string[] - Default:
["imports"]
Customize the imports field in package.json which are used to provide the internal requests of a package (requests starting with # are considered internal).
e.g.
When this configuration is ["testImports", "imports"], the result of import value from '#foo' in current package is src/test/foo.js.
resolve.mainFields
- Type:
string[] - Default: Based on the target option
Controls the priority of fields in a package.json used to locate a package's entry file. It is the ordered list of package.json fields Rspack will try when resolving an npm package's entry point.
If target is 'web', 'webworker', or not specified, the default value is ["browser", "module", "main"].
For any other target (including 'node'), the default value is ["module", "main"].
For example, consider an arbitrary library called foo with a package.json that contains the following fields:
When import foo from 'foo', Rspack resolves to the module in the browser field, because the browser field has the highest priority in mainFields array.
Note that the exports field takes precedence over mainFields. If an entry is resolved via exports, Rspack ignores the browser, module, and main fields.
For example, with the following package.json, lib is resolved via the exports field to ./dist/index.mjs, and the main field is ignored.
resolve.mainFiles
- Type:
string[] - default:
["index"]
The filename suffix when resolving directories, e.g. require('. /dir/') will try to resolve '. /dir/index'.
Can configure multiple filename suffixes:
resolve.modules
- Type:
string[] - Default:
["node_modules"]
The name of the directory to use when resolving dependencies.
resolve.preferRelative
- Type:
boolean - Default:
false
When enabled, require('file') will first look for the . /file file in the current directory, not <modules>/file.
resolve.preferAbsolute
- Type:
boolean - Default:
false
Opt for absolute paths when resolving, in relation to resolve.roots.
resolve.tsConfig
- Type:
string | object | undefined - Default:
undefined
The replacement of tsconfig-paths-webpack-plugin in Rspack.
resolve.tsConfig.configFile
- Type:
string
If you pass the path of tsconfig.json via the option, Rspack will try to resolve modules based on the paths and baseUrl of tsconfig.json, functionally equivalent to tsconfig-paths-webpack-plugin.
resolve.tsConfig.references
- Type:
string[] | "auto" | undefined - Default:
undefined
Supports tsconfig project references defined in tsconfig-paths-webpack-plugin.
The list of tsconfig paths can be provided manually, or you may specify auto to read the paths list from tsconfig.references automatically.
This feature is disabled when the value is undefined.
resolve.fullySpecified
- Type:
boolean - Default:
false
No longer resolve extensions, no longer resolve mainFiles in package.json (but does not affect requests from mainFiles, browser, alias).
resolve.restrictions
- Type:
string[] - Default:
[]
A list of resolve restrictions to restrict the paths that a request can be resolved on.
resolve.roots
- Type:
string[] - Default:
[]
A list of directories where server-relative URLs (beginning with '/') are resolved. It defaults to the context configuration option. On systems other than Windows, these requests are initially resolved as an absolute path.
resolve.symlinks
- Type:
boolean - Default:
true
Whether to resolve symlinks to their symlinked location.
When enabled, symlinked resources are resolved to their real path, not their symlinked location. Note that this may cause module resolution to fail when using tools that symlink packages (like npm link).
resolve.byDependency
- Type:
Record<string, Resolve>.
Customize the Resolve configuration based on the module type.
resolve.pnp
- Type:
boolean - Default:
!!process.versions.pnp
When enabled, it will enable Yarn PnP resolution.
It's enabled by default if !!process.versions.pnp is true, which means the application is running in Yarn PnP environments.
Example:

