diff --git a/npm-packages/meteor-rspack/lib/mergeRulesSplitOverlap.js b/npm-packages/meteor-rspack/lib/mergeRulesSplitOverlap.js index 5fd2e03dfb..8dc9c863d0 100644 --- a/npm-packages/meteor-rspack/lib/mergeRulesSplitOverlap.js +++ b/npm-packages/meteor-rspack/lib/mergeRulesSplitOverlap.js @@ -252,6 +252,25 @@ export function cleanOmittedPaths(obj, options = {}) { return result; } +/** + * Normalizes externals configuration to ensure consistent handling. + * @param {Object} config - The configuration object + * @returns {Object} - The normalized configuration + */ +function normalizeExternals(config) { + if (!config || !config.externals) return config; + + // Create a deep clone of the config to avoid modifying the original + const result = { ...config }; + + // If externals is not an array, convert it to an array + if (!Array.isArray(result.externals)) { + result.externals = [result.externals]; + } + + return result; +} + /** * Merges webpack/rspack configs with smart handling of overlapping rules. * @@ -259,6 +278,9 @@ export function cleanOmittedPaths(obj, options = {}) { * @returns {Object} Merged config */ export function mergeSplitOverlap(...configs) { + // Normalize externals in all configs before merging + const normalizedConfigs = configs.map(normalizeExternals); + return mergeWithCustomize({ customizeArray(a, b, key) { if (key === 'module.rules') { @@ -287,5 +309,5 @@ export function mergeSplitOverlap(...configs) { // fall through to default merging return undefined; } - })(...configs); + })(...normalizedConfigs); }