source: frontend/node_modules/webpack/lib/wasm-sync/WebAssemblyInInitialChunkError.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[9af201e]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3*/
4
5"use strict";
6
7const WebpackError = require("../errors/WebpackError");
8
9/** @typedef {import("../ChunkGraph")} ChunkGraph */
10/** @typedef {import("../Module")} Module */
11/** @typedef {import("../ModuleGraph")} ModuleGraph */
12/** @typedef {import("../RequestShortener")} RequestShortener */
13
14/**
15 * Gets initial module chains.
16 * @param {Module} module module to get chains from
17 * @param {ModuleGraph} moduleGraph the module graph
18 * @param {ChunkGraph} chunkGraph the chunk graph
19 * @param {RequestShortener} requestShortener to make readable identifiers
20 * @returns {string[]} all chains to the module
21 */
22const getInitialModuleChains = (
23 module,
24 moduleGraph,
25 chunkGraph,
26 requestShortener
27) => {
28 const queue = [
29 { head: module, message: module.readableIdentifier(requestShortener) }
30 ];
31 /** @type {Set<string>} */
32 const results = new Set();
33 /** @type {Set<string>} */
34 const incompleteResults = new Set();
35 /** @type {Set<Module>} */
36 const visitedModules = new Set();
37
38 for (const chain of queue) {
39 const { head, message } = chain;
40 let final = true;
41 /** @type {Set<Module>} */
42 const alreadyReferencedModules = new Set();
43 for (const connection of moduleGraph.getIncomingConnections(head)) {
44 const newHead = connection.originModule;
45 if (newHead) {
46 if (
47 !chunkGraph.getModuleChunks(newHead).some((c) => c.canBeInitial())
48 ) {
49 continue;
50 }
51 final = false;
52 if (alreadyReferencedModules.has(newHead)) continue;
53 alreadyReferencedModules.add(newHead);
54 const moduleName = newHead.readableIdentifier(requestShortener);
55 const detail = connection.explanation
56 ? ` (${connection.explanation})`
57 : "";
58 const newMessage = `${moduleName}${detail} --> ${message}`;
59 if (visitedModules.has(newHead)) {
60 incompleteResults.add(`... --> ${newMessage}`);
61 continue;
62 }
63 visitedModules.add(newHead);
64 queue.push({
65 head: newHead,
66 message: newMessage
67 });
68 } else {
69 final = false;
70 const newMessage = connection.explanation
71 ? `(${connection.explanation}) --> ${message}`
72 : message;
73 results.add(newMessage);
74 }
75 }
76 if (final) {
77 results.add(message);
78 }
79 }
80 for (const result of incompleteResults) {
81 results.add(result);
82 }
83 return [...results];
84};
85
86class WebAssemblyInInitialChunkError extends WebpackError {
87 /**
88 * Creates an instance of WebAssemblyInInitialChunkError.
89 * @param {Module} module WASM module
90 * @param {ModuleGraph} moduleGraph the module graph
91 * @param {ChunkGraph} chunkGraph the chunk graph
92 * @param {RequestShortener} requestShortener request shortener
93 */
94 constructor(module, moduleGraph, chunkGraph, requestShortener) {
95 const moduleChains = getInitialModuleChains(
96 module,
97 moduleGraph,
98 chunkGraph,
99 requestShortener
100 );
101 const message = `WebAssembly module is included in initial chunk.
102This is not allowed, because WebAssembly download and compilation must happen asynchronous.
103Add an async split point (i. e. import()) somewhere between your entrypoint and the WebAssembly module:
104${moduleChains.map((s) => `* ${s}`).join("\n")}`;
105
106 super(message);
107
108 /** @type {string} */
109 this.name = "WebAssemblyInInitialChunkError";
110 this.hideStack = true;
111 this.module = module;
112 }
113}
114
115module.exports = WebAssemblyInInitialChunkError;
Note: See TracBrowser for help on using the repository browser.