[Bug]: modern-module: chunk shared by multiple entries registers modules only in the first entry's runtime
With library.type: 'modern-module' and two entries importing the same CommonJS module, the shared chunk imports only the first entry's runtime chunk, so the second entry throws on load.
Repro
// src/shared.cjs
exports.value = 42;
// src/a.js
import shared from './shared.cjs';
export const a = () => shared.value;
// src/b.js
import shared from './shared.cjs';
export const b = () => shared.value;
// rspack.config.mjs
export default {
mode: 'production',
target: 'node',
entry: { a: './src/a.js', b: './src/b.js' },
output: { library: { type: 'modern-module' } },
optimization: { minimize: false },
};npx rspack build && node dist/a.mjs && node dist/b.mjs
a.mjs imports runtime 612.mjs, b.mjs imports runtime 231.mjs, and the shared chunk 632.mjs calls __webpack_require__.add({395: …}) on 612.mjs only.
Expected
Both entries load.
Actual
node dist/b.mjs throws TypeError: __webpack_modules__[moduleId] is not a function (Cannot read properties of undefined (reading 'call') if the CJS module uses top-level this).
Same with runtimeChunk: true, splitChunks: false, or output.asyncChunks: false. library.type: 'module' works.
Versions
@rspack/core 2.2.7 and 2.2.8-canary-9775bbdd-20260927173450, Node 24.16.
Workaround
optimization.runtimeChunk: 'single'.
Possible cause
optimize_runtime_chunks gives each entrypoint its own runtime chunk, but EsmLibraryPlugin::get_entrypoint uses only chunk.groups().iter().next(), so a chunk in several entrypoints gets one runtime.
Source: web-infra-dev/rspack