diff --git a/crates/rspack_core/src/exports_info.rs b/crates/rspack_core/src/exports_info.rs index b76c882e9b9..cdeae4ebdab 100644 --- a/crates/rspack_core/src/exports_info.rs +++ b/crates/rspack_core/src/exports_info.rs @@ -1293,11 +1293,17 @@ impl ExportInfoId { if !export_info.target_is_set || export_info.target.is_empty() { return FindTargetRetEnum::Undefined; } - let raw_target = export_info - .get_max_target_readonly() - .values() - .next() - .cloned(); + + let raw_target = if export_info.max_target_is_set { + export_info + .get_max_target_readonly() + .values() + .next() + .cloned() + } else { + export_info._get_max_target().values().next().cloned() + }; + let Some(raw_target) = raw_target else { return FindTargetRetEnum::Undefined; }; @@ -1718,6 +1724,8 @@ impl ExportInfo { map } + /// Panics: + /// Panics if max target is not set before. fn get_max_target_readonly(&self) -> &HashMap, ExportInfoTargetValue> { assert!(self.max_target_is_set); &self.max_target diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/index.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/index.js new file mode 100644 index 00000000000..09eff7dcb6d --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/index.js @@ -0,0 +1,5 @@ +import { QueryClient } from 'mocklib'; + +it("should compile", () => { + expect(QueryClient).toBe(1) +}); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/core.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/core.js new file mode 100644 index 00000000000..40cf7612cc1 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/core.js @@ -0,0 +1,2 @@ +export { QueryClient } from './queryclient'; +export * from './empty'; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/empty.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/empty.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/lib.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/lib.js new file mode 100644 index 00000000000..4b0e0413762 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/lib.js @@ -0,0 +1 @@ +export * from './core'; diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/package.json b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/package.json new file mode 100644 index 00000000000..81f0a344a40 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/package.json @@ -0,0 +1,8 @@ +{ + "name": "mocklib", + "main": "./lib.js", + "module": "./lib.js", + "sideEffects": [ + "lib.js" + ] +} \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/queryclient.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/queryclient.js new file mode 100644 index 00000000000..8bf3dbf7e52 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/queryclient.js @@ -0,0 +1 @@ +export var QueryClient = 1; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/rspack.config.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/rspack.config.js new file mode 100644 index 00000000000..749dca0efc0 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/rspack.config.js @@ -0,0 +1,13 @@ +/**@type {import("@rspack/core").Configuration}*/ +module.exports = { + mode: "development", + entry: { + main: "./index.js" + }, + optimization: { + providedExports: true, + usedExports: true, + concatenateModules: true, + minimize: false + }, +};