MixedExportsWarning.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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} MixedExportsDetails
  9. * @property {string} name the entry, by name
  10. * @property {string[]} named the named exports sitting beside the default
  11. */
  12. class MixedExportsWarning extends WebpackError {
  13. /**
  14. * Creates an instance of MixedExportsWarning.
  15. * @param {MixedExportsDetails[]} entries the entries that mix them
  16. * @param {string} type the library type they are built for
  17. */
  18. constructor(entries, type) {
  19. const list = entries
  20. .map(
  21. (entry) =>
  22. `\n ${entry.name} (default and ${entry.named.length}: ${entry.named
  23. .slice(0, 3)
  24. .join(", ")}${entry.named.length > 3 ? ", …" : ""})`
  25. )
  26. .join("");
  27. super(
  28. `mixed exports: ${entries.length} ${entries.length === 1 ? "entry exports" : "entries export"} a default beside named exports for the '${type}' library:${list}\nA consumer calling 'require()' gets the namespace object, so the default arrives as '.default' rather than as the value itself. Exporting only a default, or only named exports, leaves no ambiguity — 'output.library.export' can also pick one.\nFor more info visit https://webpack.js.org/configuration/output/#outputlibraryexport`
  29. );
  30. /** @type {string} */
  31. this.name = "MixedExportsWarning";
  32. }
  33. }
  34. module.exports = MixedExportsWarning;