CircularDependenciesWarning.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Alexander Akait @alexander-akait
  4. */
  5. "use strict";
  6. const WebpackError = require("./WebpackError");
  7. /**
  8. * @typedef {object} CircularDependencyDetails
  9. * @property {number} size how many modules can all reach each other
  10. * @property {string} cycle the shortest cycle through one of them
  11. */
  12. class CircularDependenciesWarning extends WebpackError {
  13. /**
  14. * Creates an instance of CircularDependenciesWarning.
  15. * @param {CircularDependencyDetails[]} groups the largest groups, biggest first
  16. * @param {number} total how many groups of modules import each other
  17. */
  18. constructor(groups, total) {
  19. const list = groups
  20. .map((group) => `\n ${group.size} modules: ${group.cycle}`)
  21. .join("");
  22. super(
  23. `circular dependencies: ${total} ${
  24. total === 1 ? "group of modules imports" : "groups of modules import"
  25. } each other synchronously, shortest cycle of each shown:${list}\nOne module of a cycle runs before the others finished, so it reads their exports as 'undefined' — or throws for a 'const' or 'class' export. Moving the shared part into a module both sides import breaks the cycle.`
  26. );
  27. /** @type {string} */
  28. this.name = "CircularDependenciesWarning";
  29. }
  30. }
  31. module.exports = CircularDependenciesWarning;