Webpack 5 entry dependOn property with UMD exports does not allow AMD loader to load dependent modules
See original GitHub issueBug report
What is the current behavior?
The newly-introduced dependOn feature to be released with Webpack 5 seems to have non-deterministic behaviour when exporting UMD modules and using a require-based (i.e. AMD) loader.
What appears to be the fundamental issue is that an import of a module that depends on another does not result in a proper import of the dependent module; e.g. if Module A depends on Module B, then a simple define([ModuleA], function(ModuleA) { ... }) does not seem to kick off a proper require of Module B.
If the current behavior is a bug, please provide the steps to reproduce.
webpack.config.js snippet:
entry: {
ModuleC: `${process.cwd()}/ModuleC`,
ModuleB: {
import: `${process.cwd()}/ModuleB`,
dependOn: 'ModuleC',
},
ModuleA: {
import: `${process.cwd()}/ModuleA`,
dependOn: ['ModuleB', 'ModuleC'],
}
},
output: {
path: `${process.cwd()}/dist`,
filename: '[name].js',
library: 'modules',
libraryTarget: 'umd'
}
Module A:
import ModuleB from './ModuleB';
import ModuleC from './ModuleC';
const ModuleA = function() {
console.log('A');
ModuleB();
ModuleC();
};
export default ModuleA;
Module B:
import ModuleC from './ModuleC';
const ModuleB = function() {
console.log('B');
ModuleC();
};
export default ModuleB;
Module C:
const ModuleC = function() {
console.log('C');
};
export default ModuleC;
Bundling these with webpack results in strange behaviour - I have created a couple of scenarios in my minimal test github repo to demonstrate this:
- In
basepage-1.html, I test out the simpler case of simply loadingModuleA(inmain-1.js) in the browser. This doesn’t ever work (breakpoints indicate that require simply returns a number like1or2). The network indicates that no attempt is made to loadModuleBorModuleC. - In
basepage-2.html, I test out the more complex case of loading all of the ModulesCthroughA(in that order, inmain-2.js). Continual refreshes of the browser sometimes allows different modules to work, but the actual output of the firstModuleX.default()call can change depending on what I assume to be the result of a race condition of the module loads.
What is the expected behavior?
- In
basepage-1.html(i.e.main-1.js), I expectModuleAto successfully loadModuleBandModuleC, resulting in an output of:
A // Here begins output of ModuleA
B
C
C
- In
basepage-2.html(i.e.main-2.js), I expect all three modules to load successfully, and the calls to the functions resulting in an output of:
C // Here begins output of ModuleC
B // Here begins output of ModuleB
C
A // Here begins output of ModuleA
B
C
C
If I remove the dependOn field from my webpack config and load the three non-dependent chunks as regular entry points, there is no race condition and all modules load properly and provide the proper output.
Other relevant information: webpack version: 5.0.0-beta.14 Node.js version: 10.18.1 Operating System: macOS Mojave 10.14.6 Additional tools:
- Any recent-ish Chrome browser version
- RequireJS (found here: https://requirejs.org/docs/release/2.3.6/minified/require.js)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (3 by maintainers)

Top Related StackOverflow Question
I am also experiencing similar weirdness with dependOn. My understanding was that the introduction of dependOn would facilitate the use case of including multiple entry scripts into an HTML page, something that was originally raised pre-v5 (see https://github.com/webpack/webpack/issues/8842).
Citing the use case in that thread by @lostPixels:
My understanding was that the above would now be possible if you defined the entries something to the effect of:
…but I’m not really sure anymore. Can anyone confirm or offer more insight?
+1 I don’t see the point of dependOn if this is not supported.