diff --git a/crates/rspack_plugin_runtime/src/module_chunk_format.rs b/crates/rspack_plugin_runtime/src/module_chunk_format.rs index 8a80a0cd17f1..5e09cee913bb 100644 --- a/crates/rspack_plugin_runtime/src/module_chunk_format.rs +++ b/crates/rspack_plugin_runtime/src/module_chunk_format.rs @@ -162,7 +162,7 @@ async fn render_chunk( if chunk.has_entry_module(&compilation.chunk_graph) { let runtime_chunk_output_name = get_runtime_chunk_output_name(compilation, chunk_ukey).await?; sources.add(RawStringSource::from(format!( - "import __webpack_require__ from '{}';\n", + "import {{ __webpack_require__ }} from '{}';\n", get_relative_path( base_chunk_output_name .trim_start_matches("/") @@ -297,6 +297,7 @@ async fn render_startup( &compilation.chunk_by_ukey, &compilation.chunk_group_by_ukey, ); + let base_chunk_output_name = get_chunk_output_name(chunk, compilation).await?; let mut dependent_load = ConcatSource::default(); diff --git a/crates/rspack_plugin_runtime/src/module_chunk_loading.rs b/crates/rspack_plugin_runtime/src/module_chunk_loading.rs index 2f8ffec50423..10cad97f84e5 100644 --- a/crates/rspack_plugin_runtime/src/module_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/module_chunk_loading.rs @@ -38,16 +38,9 @@ async fn runtime_requirements_in_tree( } RuntimeGlobals::EXTERNAL_INSTALL_CHUNK if is_enabled_for_chunk => { has_chunk_loading = true; - if compilation - .chunk_graph - .get_number_of_entry_modules(chunk_ukey) - > 0 - { - continue; - } else { - compilation - .add_runtime_module(chunk_ukey, ExportWebpackRequireRuntimeModule::new().boxed())?; - } + + compilation + .add_runtime_module(chunk_ukey, ExportWebpackRequireRuntimeModule::new().boxed())?; } RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS if is_enabled_for_chunk => { diff --git a/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs b/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs index c08a34dc2d89..a38daa1cbe21 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs @@ -1,6 +1,8 @@ use rspack_collections::Identifier; use rspack_core::{Compilation, RuntimeGlobals, RuntimeModule, impl_runtime_module}; +const EXPORT_TEMP_NAME: &str = "__webpack_require_temp__"; + #[impl_runtime_module] #[derive(Debug, Default)] pub struct ExportWebpackRequireRuntimeModule { @@ -20,7 +22,11 @@ impl RuntimeModule for ExportWebpackRequireRuntimeModule { } async fn generate(&self, _compilation: &Compilation) -> rspack_error::Result { - Ok(format!("export default {};", RuntimeGlobals::REQUIRE)) + Ok(format!( + "var {EXPORT_TEMP_NAME} = {};\nexport {{ {EXPORT_TEMP_NAME} as {} }};\n", + RuntimeGlobals::REQUIRE, + RuntimeGlobals::REQUIRE + )) } fn should_isolate(&self) -> bool { diff --git a/tests/rspack-test/configCases/module/dependOn-entries/test.filter.js b/tests/rspack-test/configCases/module/dependOn-entries/test.filter.js index 1a4faac27363..be96fcb74042 100644 --- a/tests/rspack-test/configCases/module/dependOn-entries/test.filter.js +++ b/tests/rspack-test/configCases/module/dependOn-entries/test.filter.js @@ -1 +1 @@ -module.exports = () => "FIXME: __webpack_require__.C is not a function" \ No newline at end of file +module.exports = () => true \ No newline at end of file