1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const WebpackError = require("../WebpackError");
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | const getInitialModuleChains = (
|
22 | module,
|
23 | moduleGraph,
|
24 | chunkGraph,
|
25 | requestShortener
|
26 | ) => {
|
27 | const queue = [
|
28 | { head: module, message: module.readableIdentifier(requestShortener) }
|
29 | ];
|
30 |
|
31 | const results = new Set();
|
32 |
|
33 | const incompleteResults = new Set();
|
34 |
|
35 | const visitedModules = new Set();
|
36 |
|
37 | for (const chain of queue) {
|
38 | const { head, message } = chain;
|
39 | let final = true;
|
40 |
|
41 | const alreadyReferencedModules = new Set();
|
42 | for (const connection of moduleGraph.getIncomingConnections(head)) {
|
43 | const newHead = connection.originModule;
|
44 | if (newHead) {
|
45 | if (!chunkGraph.getModuleChunks(newHead).some(c => c.canBeInitial()))
|
46 | continue;
|
47 | final = false;
|
48 | if (alreadyReferencedModules.has(newHead)) continue;
|
49 | alreadyReferencedModules.add(newHead);
|
50 | const moduleName = newHead.readableIdentifier(requestShortener);
|
51 | const detail = connection.explanation
|
52 | ? ` (${connection.explanation})`
|
53 | : "";
|
54 | const newMessage = `${moduleName}${detail} --> ${message}`;
|
55 | if (visitedModules.has(newHead)) {
|
56 | incompleteResults.add(`... --> ${newMessage}`);
|
57 | continue;
|
58 | }
|
59 | visitedModules.add(newHead);
|
60 | queue.push({
|
61 | head: newHead,
|
62 | message: newMessage
|
63 | });
|
64 | } else {
|
65 | final = false;
|
66 | const newMessage = connection.explanation
|
67 | ? `(${connection.explanation}) --> ${message}`
|
68 | : message;
|
69 | results.add(newMessage);
|
70 | }
|
71 | }
|
72 | if (final) {
|
73 | results.add(message);
|
74 | }
|
75 | }
|
76 | for (const result of incompleteResults) {
|
77 | results.add(result);
|
78 | }
|
79 | return Array.from(results);
|
80 | };
|
81 |
|
82 | module.exports = class WebAssemblyInInitialChunkError extends WebpackError {
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | constructor(module, moduleGraph, chunkGraph, requestShortener) {
|
90 | const moduleChains = getInitialModuleChains(
|
91 | module,
|
92 | moduleGraph,
|
93 | chunkGraph,
|
94 | requestShortener
|
95 | );
|
96 | const message = `WebAssembly module is included in initial chunk.
|
97 | This is not allowed, because WebAssembly download and compilation must happen asynchronous.
|
98 | Add an async split point (i. e. import()) somewhere between your entrypoint and the WebAssembly module:
|
99 | ${moduleChains.map(s => `* ${s}`).join("\n")}`;
|
100 |
|
101 | super(message);
|
102 | this.name = "WebAssemblyInInitialChunkError";
|
103 | this.hideStack = true;
|
104 | this.module = module;
|
105 | }
|
106 | };
|