diff --git a/crates/rspack_plugin_mf/src/container/container_entry_module.rs b/crates/rspack_plugin_mf/src/container/container_entry_module.rs index afad80b50fa3..eb1e688ef6fd 100644 --- a/crates/rspack_plugin_mf/src/container/container_entry_module.rs +++ b/crates/rspack_plugin_mf/src/container/container_entry_module.rs @@ -399,8 +399,11 @@ var init = function(shareScope, initScope) {{ share_scope_map = runtime_template.render_runtime_globals(&RuntimeGlobals::SHARE_SCOPE_MAP), share_scope = json_stringify_str(match &self.share_scope { ShareScope::Single(s) => s.as_str(), + ShareScope::Multiple(scopes) if scopes.len() == 1 => scopes[0].as_str(), ShareScope::Multiple(_) => { - panic!("ContainerEntryModule: enhanced=false only supports string share scope") + panic!( + "ContainerEntryModule: enhanced=false only supports string or single-item array share scope" + ) } }), initialize_sharing = diff --git a/tests/rspack-test/configCases/container/single-array-share-scope/index.js b/tests/rspack-test/configCases/container/single-array-share-scope/index.js new file mode 100644 index 000000000000..2971abd2baa6 --- /dev/null +++ b/tests/rspack-test/configCases/container/single-array-share-scope/index.js @@ -0,0 +1,8 @@ +it("should support single-item shareScope array in non-enhanced container", async () => { + const container = __non_webpack_require__("./container-file.js"); + expect(container).toBeTypeOf("object"); + expect(container.get).toBeTypeOf("function"); + const testFactory = await container.get("./test"); + expect(testFactory).toBeTypeOf("function"); + expect(testFactory()).toBe("test"); +}); diff --git a/tests/rspack-test/configCases/container/single-array-share-scope/rspack.config.js b/tests/rspack-test/configCases/container/single-array-share-scope/rspack.config.js new file mode 100644 index 000000000000..7da662d98b18 --- /dev/null +++ b/tests/rspack-test/configCases/container/single-array-share-scope/rspack.config.js @@ -0,0 +1,21 @@ +const { ContainerPlugin } = require("@rspack/core").container; + +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + output: { + pathinfo: true + }, + plugins: [ + new ContainerPlugin({ + name: "container", + filename: "container-file.js", + library: { + type: "commonjs-module" + }, + shareScope: ["default"], + exposes: { + "./test": "./test" + } + }) + ] +}; diff --git a/tests/rspack-test/configCases/container/single-array-share-scope/test.js b/tests/rspack-test/configCases/container/single-array-share-scope/test.js new file mode 100644 index 000000000000..1caa3322d9a9 --- /dev/null +++ b/tests/rspack-test/configCases/container/single-array-share-scope/test.js @@ -0,0 +1 @@ +module.exports = "test";