[Feature]: Warn when MultiCompiler emits conflicting assets to the same output file
What problem does this feature solve?
When multiple compilers emit different content to the same output file, one compiler's asset can silently overwrite another's. Rspack currently does not report a cross-compiler asset conflict.
Within a single compilation, Rspack already detects conflicting content for the same filename and reports an error:
Conflict: Multiple assets emit different content to the same filename ...However, this check is scoped to the compilation's own assets, so it does not catch conflicts between compilers in a MultiCompiler.
This is particularly difficult to debug in dev mode, where multiple compilers can share an in-memory output filesystem. The build appears successful, but the browser may receive a bundle generated by another compiler. The resulting runtime errors do not clearly point to an output conflict.
Examples from Rsbuild
Rsbuild's environments configuration uses multiple Rspack compilers. Users have encountered this problem when environments share output paths:
- rsbuild#7869: Two environments generated
static/js/lib-polyfill.jswith different contents. In dev mode, loading the other environment's polyfill chunk could leave requiredcore-jsmodules missing and causeRuntimeError: factory is undefined. - rsbuild#6646: A multi-environment Module Federation setup reported infinite reloads. Although Rsbuild addressed the reload behavior separately, the investigation also highlighted the need for separate output paths to prevent environments from overwriting each other's artifacts.
A warning at the bundler level would make these configuration problems much easier to identify.
What does the proposed API of configuration look like?
Add automatic asset conflict detection across compilers in a MultiCompiler, with a warning when different compilers emit different content to the same resolved output file. No new configuration should be necessary for the default behavior.
The detection should:
- Compare resolved output paths within the shared output filesystem, rather than filenames alone. Identical filenames in separate output directories should be allowed.
- Allow multiple compilers to emit identical content to the same output file without warning.
- Work in dev/watch mode, including in-memory output and subsequent rebuilds. A rebuild of only one compiler should still be checked against assets from the other compilers.
- Identify the conflicting output file and compiler names (or indices when unnamed), and suggest using separate output directories or unique asset filenames.
- Surface the warning through compilation stats so dev servers and higher-level tools such as Rsbuild can display it.
For example:
WARNING: Compilers "web" and "emailTemplate" emit different content to the same output file:
/path/to/dist/static/js/lib-polyfill.js
One compiler's asset may overwrite the other's. Use separate output directories or unique asset filenames for each compiler.Source: web-infra-dev/rspack