resolve.extensions

  • Type: string[]
  • Default: ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json']
  • Version: >= 1.1.9

Automatically resolve file extensions when importing modules. This means you can import files without explicitly writing their extensions.

For example, if importing './index', Rsbuild will try to resolve using the following order

  • ./index.ts
  • ./index.tsx
  • ./index.mjs
  • ./index.js
  • ./index.jsx
  • ./index.json
TIP

It is not recommended to omit .vue or other custom import extension names using resolve.extensions, as this may interfere IDE and type support.

Example

The value of resolve.extensions overrides the default value of Rsbuild:

rsbuild.config.ts
export default {
  resolve: {
    extensions: ['.ts', '.tsx', '.js'],
  },
};

Rspack Config

resolve.extensions is provided by Rspack, see Rspack - resolve.extensions.

You can also configure it using tools.rspack:

rsbuild.config.ts
export default {
  tools: {
    rspack: {
      resolve: {
        extensions: ['.ts', '.tsx', '.js'],
      },
    },
  },
};

The difference between them is how the configuration is merged.

tools.rspack merges the configuration arrays based on webpack-merge, which means tools.rspack.resolve.extensions will merge with the default value of Rsbuild, rather than overriding it.