rspack
                                
                                 rspack copied to clipboard
                                
                                    rspack copied to clipboard
                            
                            
                            
                        [Bug]: Panic Module should be added before using (Location: crates/rspack_core/src/chunk_graph/chunk_graph_module.rs:74)
System Info
@rsbuild/core: 1.0.1-beta.9 (but happens on earlier version as well)
Details
When I start rsbuild, it needs to run the compiling... step twice (I am not sure exactly why)
I have noticed that rspack will crash if I try to access the page before the second compiling... step is done. If I wait, the page will load fine.
start   Compiling...
● web ━━━━━━━━━━━━━━━━━━━━━━━━━ (100%) emitting after emit                                                                                                                ready   Compiled in 13.2 s (web)
start   Compiling...
● web ━━━━━━━━━━━━━━━━━━━━━━━━━ (70%) sealing dependencies                                                                                                                Panic occurred at runtime. Please file an issue on GitHub with the backtrace below: https://github.com/web-infra-dev/rspack/issues
Message:  Module(builtin:react-refresh-loader!builtin:swc-loader??ruleSet[1].rules[3].use[0]!/<..>./some-file.js) should be added before using
Location: crates/rspack_core/src/chunk_graph/chunk_graph_module.rs:74
Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 1: _ZN6v8impl12_GLOBAL__N_123FunctionCallbackWrapper6InvokeERKN2v820FunctionCallbackInfoINS2_5ValueEEE
    at <unknown source file>
 2: _ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE
    at <unknown source file>
 3: _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEENS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EEPmi
    at <unknown source file>
 4: _ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE
    at <unknown source file>
 5: Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit
    at <unknown source file>
Aborted (core dumped)
Given what's mentioned in the error message, I am filing this bug report.
Reproduce Steps
I have seen it failing with two different files.
One file has some code that does this:
async function getModule(code) {
  function encode(code) {
    return Buffer.from(code).toString('base64');
  }
  const importStatement = `data:text/javascript;base64,${encode(code)}`;
  return import(importStatement);
}
If I remove the import(importStatement) line, I get the same error but this time because of
[email protected]/node_modules/mocha/lib/mocha.js
which is imported like this (using require or import causes the same error)
const mocha = require('mocha');