Skip to content

Commit baada55

Browse files
committed
add error type and request url when dynamic chunk failed to load (webpack#4595)
1 parent ef6ab68 commit baada55

File tree

13 files changed

+29
-18
lines changed

13 files changed

+29
-18
lines changed

lib/JsonpMainTemplatePlugin.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ class JsonpMainTemplatePlugin {
5757
this.indent(`script.setAttribute("nonce", ${this.requireFn}.nc);`),
5858
"}",
5959
`script.src = ${this.requireFn}.p + ${scriptSrcPath};`,
60-
`var timeout = setTimeout(onScriptComplete, ${chunkLoadTimeout});`,
60+
"var timeout = setTimeout(function(){",
61+
this.indent([
62+
"onScriptComplete({type:'timeout', target:script});",
63+
]),
64+
`}, ${chunkLoadTimeout});`,
6165
"script.onerror = script.onload = onScriptComplete;",
62-
"function onScriptComplete() {",
66+
"function onScriptComplete(event) {",
6367
this.indent([
6468
"// avoid mem leaks in IE.",
6569
"script.onerror = script.onload = null;",
@@ -68,7 +72,14 @@ class JsonpMainTemplatePlugin {
6872
"if(chunk !== 0) {",
6973
this.indent([
7074
"if(chunk) {",
71-
this.indent("chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));"),
75+
this.indent([
76+
"var errorType = event.type === 'load' ? 'missing' : event.type;",
77+
"var realSrc = event.target.src;",
78+
"var error = new Error('Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')');",
79+
"error.type = errorType;",
80+
"error.request = realSrc;",
81+
"chunk[1](error);"
82+
]),
7283
"}",
7384
"installedChunks[chunkId] = undefined;"
7485
]),

test/statsCases/aggressive-splitting-on-demand/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cd45585186d59208602b.js 1.96 kB 1 [emitted]
66
6b94c231e016c5aaccdb.js 1.94 kB 2 [emitted]
77
fd0985cee894c4f3f1a6.js 1.94 kB 3 [emitted]
88
d9fc46873c8ea924b895.js 979 bytes 4 [emitted]
9-
a773fee259e5a284dea9.js 7.47 kB 6 [emitted] main
9+
a773fee259e5a284dea9.js 7.82 kB 6 [emitted] main
1010
b08c507d4e1e05cbab45.js 985 bytes 9 [emitted]
1111
5d50e858fe6e559aa47c.js 977 bytes 11 [emitted]
1212
Entrypoint main = a773fee259e5a284dea9.js

test/statsCases/chunks/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Time: Xms
44
0.bundle.js 238 bytes 0 [emitted]
55
1.bundle.js 102 bytes 1 [emitted]
66
2.bundle.js 182 bytes 2 [emitted]
7-
bundle.js 6.1 kB 3 [emitted] main
7+
bundle.js 6.45 kB 3 [emitted] main
88
chunk {0} 0.bundle.js 54 bytes {3} [rendered]
99
> [0] (webpack)/test/statsCases/chunks/index.js 3:0-16
1010
[3] (webpack)/test/statsCases/chunks/c.js 54 bytes {0} [built]

test/statsCases/commons-chunk-min-size-0/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Hash: dc6038bec87a57d1a45e
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
entry-1.js 25 bytes 0 [emitted] entry-1
5-
vendor-1.js 6.76 kB 1 [emitted] vendor-1
5+
vendor-1.js 7.11 kB 1 [emitted] vendor-1
66
[0] (webpack)/test/statsCases/commons-chunk-min-size-0/modules/a.js 22 bytes {1} [built]
77
[1] (webpack)/test/statsCases/commons-chunk-min-size-0/modules/b.js 22 bytes {1} [built]
88
[2] (webpack)/test/statsCases/commons-chunk-min-size-0/modules/c.js 22 bytes {1} [built]

test/statsCases/commons-plugin-issue-4980/expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Child
55
Asset Size Chunks Chunk Names
66
app.js 1.27 kB 0 [emitted] app
77
vendor.bd2b4219dfda1a951495.js 443 bytes 1 [emitted] vendor
8-
runtime.js 5.78 kB 2 [emitted] runtime
8+
runtime.js 6.12 kB 2 [emitted] runtime
99
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
1010
[./entry-1.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-1.js 67 bytes {0} [built]
1111
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
@@ -16,7 +16,7 @@ Child
1616
Asset Size Chunks Chunk Names
1717
app.js 1.32 kB 0 [emitted] app
1818
vendor.bd2b4219dfda1a951495.js 443 bytes 1 [emitted] vendor
19-
runtime.js 5.78 kB 2 [emitted] runtime
19+
runtime.js 6.12 kB 2 [emitted] runtime
2020
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
2121
[./entry-2.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-2.js 67 bytes {0} [built]
2222
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]

test/statsCases/import-weak/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Hash: d34cc0bd2faeb65c3282
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
0.js 99 bytes 0 [emitted]
5-
entry.js 6.22 kB 1 [emitted] entry
5+
entry.js 6.57 kB 1 [emitted] entry
66
[0] (webpack)/test/statsCases/import-weak/modules/b.js 22 bytes {0} [built]
77
[1] (webpack)/test/statsCases/import-weak/entry.js 120 bytes {1} [built]
88
[2] (webpack)/test/statsCases/import-weak/modules/a.js 37 bytes [built]

test/statsCases/limit-chunk-count-plugin/expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Child
1616
Time: Xms
1717
Asset Size Chunks Chunk Names
1818
0.bundle.js 601 bytes 0 [emitted]
19-
bundle.js 6.12 kB 1 [emitted] main
19+
bundle.js 6.47 kB 1 [emitted] main
2020
chunk {0} 0.bundle.js 118 bytes {1} [rendered]
2121
[1] (webpack)/test/statsCases/limit-chunk-count-plugin/a.js 22 bytes {0} [built]
2222
[2] (webpack)/test/statsCases/limit-chunk-count-plugin/b.js 22 bytes {0} [built]
@@ -31,7 +31,7 @@ Child
3131
Asset Size Chunks Chunk Names
3232
0.bundle.js 454 bytes 0 [emitted]
3333
1.bundle.js 182 bytes 1 [emitted]
34-
bundle.js 6.11 kB 2 [emitted] main
34+
bundle.js 6.46 kB 2 [emitted] main
3535
chunk {0} 0.bundle.js 74 bytes {2} [rendered]
3636
[1] (webpack)/test/statsCases/limit-chunk-count-plugin/a.js 22 bytes {0} [built]
3737
[3] (webpack)/test/statsCases/limit-chunk-count-plugin/c.js 30 bytes {0} [built]
@@ -48,7 +48,7 @@ Child
4848
0.bundle.js 182 bytes 0 [emitted]
4949
1.bundle.js 204 bytes 1 [emitted]
5050
2.bundle.js 283 bytes 2 [emitted]
51-
bundle.js 6.1 kB 3 [emitted] main
51+
bundle.js 6.45 kB 3 [emitted] main
5252
chunk {0} 0.bundle.js 44 bytes {2} {3} [rendered]
5353
[2] (webpack)/test/statsCases/limit-chunk-count-plugin/b.js 22 bytes {0} [built]
5454
[5] (webpack)/test/statsCases/limit-chunk-count-plugin/e.js 22 bytes {0} [built]

test/statsCases/named-chunks-plugin-async/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Time: Xms
33
Asset Size Chunks Chunk Names
44
chunk-containing-__a_js.js 266 bytes chunk-containing-__a_js [emitted]
55
chunk-containing-__b_js.js 123 bytes chunk-containing-__b_js [emitted]
6-
entry.js 5.99 kB entry [emitted] entry
6+
entry.js 6.34 kB entry [emitted] entry
77
[0] (webpack)/test/statsCases/named-chunks-plugin-async/modules/b.js 22 bytes {chunk-containing-__b_js} [built]
88
[1] (webpack)/test/statsCases/named-chunks-plugin-async/entry.js 47 bytes {entry} [built]
99
[2] (webpack)/test/statsCases/named-chunks-plugin-async/modules/a.js 37 bytes {chunk-containing-__a_js} [built]

test/statsCases/named-chunks-plugin/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Hash: ac63e5be974bcdfea3a3
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
entry.js 345 bytes entry [emitted] entry
5-
manifest.js 5.78 kB manifest [emitted] manifest
5+
manifest.js 6.13 kB manifest [emitted] manifest
66
vendor.js 397 bytes vendor [emitted] vendor
77
[0] multi ./modules/a ./modules/b 40 bytes {vendor} [built]
88
[./entry.js] (webpack)/test/statsCases/named-chunks-plugin/entry.js 72 bytes {entry} [built]

test/statsCases/optimize-chunks/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Time: Xms
88
4.js 162 bytes 4, 6 [emitted] chunk
99
5.js 306 bytes 5, 3 [emitted] cir2 from cir1
1010
6.js 80 bytes 6 [emitted] ac in ab
11-
main.js 6.78 kB 7 [emitted] main
11+
main.js 7.13 kB 7 [emitted] main
1212
chunk {0} 0.js (cir1) 81 bytes {3} {5} {7} [rendered]
1313
> duplicate cir1 from cir2 [6] (webpack)/test/statsCases/optimize-chunks/circular2.js 1:0-79
1414
> duplicate cir1 [7] (webpack)/test/statsCases/optimize-chunks/index.js 13:0-54

0 commit comments

Comments
 (0)