{"id":"e5b2ae8fd5ea5689","repo":"webpack/webpack","slug":"optimization-concatenatemodules-can-t-be-used-with","errorCode":null,"errorMessage":"optimization.concatenateModules can't be used with cacheUnaffected as module concatenation is a global effect","messagePattern":"optimization\\.concatenateModules can't be used with cacheUnaffected as module concatenation is a global effect","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/optimize/ModuleConcatenationPlugin.js","lineNumber":109,"sourceCode":" * Format bailout reason.\n * @param {string} msg message\n * @returns {string} formatted message\n */\nconst formatBailoutReason = (msg) => `ModuleConcatenation bailout: ${msg}`;\n\nconst PLUGIN_NAME = \"ModuleConcatenationPlugin\";\n\nclass ModuleConcatenationPlugin {\n\t/**\n\t * Applies the plugin by registering its hooks on the compiler.\n\t * @param {Compiler} compiler the compiler instance\n\t * @returns {void}\n\t */\n\tapply(compiler) {\n\t\tconst { _backCompat: backCompat } = compiler;\n\t\tcompiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {\n\t\t\tif (compilation.moduleMemCaches) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"optimization.concatenateModules can't be used with cacheUnaffected as module concatenation is a global effect\"\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst moduleGraph = compilation.moduleGraph;\n\t\t\t/** @type {Map<Module, string | ((requestShortener: RequestShortener) => string)>} */\n\t\t\tconst bailoutReasonMap = new Map();\n\n\t\t\t/**\n\t\t\t * Sets bailout reason.\n\t\t\t * @param {Module} module the module\n\t\t\t * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason\n\t\t\t */\n\t\t\tconst setBailoutReason = (module, reason) => {\n\t\t\t\tsetInnerBailoutReason(module, reason);\n\t\t\t\tmoduleGraph\n\t\t\t\t\t.getOptimizationBailout(module)\n\t\t\t\t\t.push(\n\t\t\t\t\t\ttypeof reason === \"function\"","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/webpack/webpack/blob/318421ea8ac81371f5171236a6efb63675576528/lib/optimize/ModuleConcatenationPlugin.js#L91-L127","documentation":"ModuleConcatenationPlugin inlines multiple modules into a single concatenated module, a graph-global transformation: a module's concatenated form depends on its neighbors. experiments.cacheUnaffected requires per-module independence, so the combination is invalid. At the compilation hook, if compilation.moduleMemCaches is set, the plugin throws before doing any work.","triggerScenarios":"experiments.cacheUnaffected: true combined with optimization.concatenateModules: true (concatenateModules defaults to true in production mode, so this trips unless explicitly disabled).","commonSituations":"Turning on cacheUnaffected in a production config where concatenateModules is on by default. Adopting the cache experiment for dev-loop speed without adjusting optimization defaults.","solutions":["Disable concatenation: optimization.concatenateModules = false.","Or disable the experiment: experiments.cacheUnaffected = false.","Disabling concatenation is the supported way to keep cacheUnaffected; expect a modest increase in module count / runtime overhead."],"exampleFix":"// before\nmodule.exports = {\n  mode: 'production', // concatenateModules defaults to true\n  experiments: { cacheUnaffected: true }\n};\n// after\nmodule.exports = {\n  mode: 'production',\n  optimization: { concatenateModules: false },\n  experiments: { cacheUnaffected: true }\n};","handlingStrategy":"validation","validationCode":"function assertCacheUnaffectedCompat(config) {\n  const cu = config.experiments && config.experiments.cacheUnaffected;\n  const concat = config.optimization && config.optimization.concatenateModules;\n  if (cu && concat !== false) {\n    throw new Error('experiments.cacheUnaffected requires optimization.concatenateModules: false');\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair experiments.cacheUnaffected with optimization.concatenateModules: false.","Remember concatenateModules is true by default in production.","Document the supported optimization matrix next to the cacheUnaffected toggle."],"tags":["config","optimization","caching","cache-unaffected","scope-hoisting"],"analyzedSha":"318421ea8ac81371f5171236a6efb63675576528","analyzedAt":"2026-08-03T19:39:56.731Z","schemaVersion":2}