Skip to content
Latchkey

Rspack "Module build failed" - Fix Loader/Builtin Errors in CI

Rspack is a Rust bundler with a Webpack-compatible API, but not every Webpack loader runs under it. "Module build failed" usually means a loader threw, an unsupported loader was used where a builtin should be, or builtin:swc-loader options are wrong.

What this error means

An rspack build (or rsbuild) fails with Module build failed naming the loader and file. It is deterministic - a loader/transform configuration problem, not flake.

rspack output
ERROR in ./src/app.tsx
  × Module build failed:
  ╰─▶ × Error: Syntax Error
       ╭─[src/app.tsx:5:1]
       5 │   return <div>hi</div>
         ·          ─
       ╰────

Common causes

A Webpack loader Rspack cannot run

Some JS-based Webpack loaders are unsupported or slow under Rspack. Rspack expects its Rust builtins (builtin:swc-loader, builtin:lightningcss-loader) for the hot path.

swc-loader options or jsc.parser mismatch

The builtin:swc-loader jsc.parser (syntax/tsx flags) does not match the file - e.g. TSX content parsed with syntax: "typescript" but tsx: false - so SWC cannot parse the JSX.

How to fix it

Use the SWC builtin loader with correct parser flags

Configure builtin:swc-loader to match the syntax, enabling tsx/jsx where needed.

rspack.config.js
// rspack.config.js
module: {
  rules: [
    {
      test: /\.[jt]sx$/,
      use: {
        loader: 'builtin:swc-loader',
        options: { jsc: { parser: { syntax: 'typescript', tsx: true } } },
      },
    },
  ],
}

Replace unsupported JS loaders

  1. Check the Rspack loader-compatibility notes for the loader that failed.
  2. Swap a JS transpile loader for builtin:swc-loader, and CSS handling for the lightningcss builtin where applicable.
  3. Keep loader test/exclude aligned with the file extensions you actually import.

How to prevent it

  • Prefer Rspack Rust builtins over JS loaders on the transform hot path.
  • Match swc-loader parser flags (tsx/jsx) to your file types.
  • Verify a Webpack loader is Rspack-compatible before porting a config.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →