source: trip-planner-front/node_modules/webpack/lib/wasm-sync/WebAssemblyInInitialChunkError.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3*/
4
5"use strict";
6
7const WebpackError = require("../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 * @param {Module} module module to get chains from
16 * @param {ModuleGraph} moduleGraph the module graph
17 * @param {ChunkGraph} chunkGraph the chunk graph
18 * @param {RequestShortener} requestShortener to make readable identifiers
19 * @returns {string[]} all chains to the module
20 */
21const getInitialModuleChains = (
22 module,
23 moduleGraph,
24 chunkGraph,
25 requestShortener
26) => {
27 const queue = [
28 { head: module, message: module.readableIdentifier(requestShortener) }
29 ];
30 /** @type {Set<string>} */
31 const results = new Set();
32 /** @type {Set<string>} */
33 const incompleteResults = new Set();
34 /** @type {Set<Module>} */
35 const visitedModules = new Set();
36
37 for (const chain of queue) {
38 const { head, message } = chain;
39 let final = true;
40 /** @type {Set<Module>} */
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
82module.exports = class WebAssemblyInInitialChunkError extends WebpackError {
83 /**
84 * @param {Module} module WASM module
85 * @param {ModuleGraph} moduleGraph the module graph
86 * @param {ChunkGraph} chunkGraph the chunk graph
87 * @param {RequestShortener} requestShortener request shortener
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.
97This is not allowed, because WebAssembly download and compilation must happen asynchronous.
98Add 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};
Note: See TracBrowser for help on using the repository browser.