Skip to content

Commit 9e5765f

Browse files
authored
Merge pull request webpack#5559 from mc-zone/feature/jsonp-error
Provide error type and request url when dynamic chunk failed to load (resolves webpack#4595)
2 parents 2d84450 + 553287d commit 9e5765f

18 files changed

Lines changed: 40 additions & 29 deletions

File tree

‎lib/JsonpMainTemplatePlugin.js‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ class JsonpMainTemplatePlugin {
6666
this.indent(`script.setAttribute("nonce", ${this.requireFn}.nc);`),
6767
"}",
6868
`script.src = ${this.requireFn}.p + ${scriptSrcPath};`,
69-
`var timeout = setTimeout(onScriptComplete, ${chunkLoadTimeout});`,
69+
"var timeout = setTimeout(function(){",
70+
this.indent([
71+
"onScriptComplete({ type: 'timeout', target: script });",
72+
]),
73+
`}, ${chunkLoadTimeout});`,
7074
"script.onerror = script.onload = onScriptComplete;",
71-
"function onScriptComplete() {",
75+
"function onScriptComplete(event) {",
7276
this.indent([
7377
"// avoid mem leaks in IE.",
7478
"script.onerror = script.onload = null;",
@@ -77,7 +81,14 @@ class JsonpMainTemplatePlugin {
7781
"if(chunk !== 0) {",
7882
this.indent([
7983
"if(chunk) {",
80-
this.indent("chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));"),
84+
this.indent([
85+
"var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
86+
"var realSrc = event && event.target && event.target.src;",
87+
"var error = new Error('Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')');",
88+
"error.type = errorType;",
89+
"error.request = realSrc;",
90+
"chunk[1](error);"
91+
]),
8192
"}",
8293
"installedChunks[chunkId] = undefined;"
8394
]),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ a0bf69daa522fbf8540c.js 1.03 kB 0 [emitted]
88
ffed75a7125f4bffaa65.js 1.99 kB 4 [emitted]
99
1eb486d42a31b58c16de.js 1.03 kB 5 [emitted]
1010
c0be493fc1372241e789.js 1.03 kB 6 [emitted]
11-
b377816b50b5f53bb16f.js 7.75 kB 7 [emitted] main
11+
b377816b50b5f53bb16f.js 8.13 kB 7 [emitted] main
1212
abfb187b6140d9d3505a.js 1.99 kB 8, 0, 5 [emitted]
1313
Entrypoint main = b377816b50b5f53bb16f.js
1414
chunk {0} c659704b2f31cae80013.js 1.8 kB {7} [rendered]

‎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 288 bytes 0 [emitted]
55
1.bundle.js 152 bytes 1 [emitted]
66
2.bundle.js 232 bytes 2 [emitted]
7-
bundle.js 6.43 kB 3 [emitted] main
7+
bundle.js 6.82 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: e2982ecf41bd0a7eda73
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
entry-1.js 81 bytes 0 [emitted] entry-1
5-
vendor-1.js 7.5 kB 1 [emitted] vendor-1
5+
vendor-1.js 7.89 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.33 kB 0 [emitted] app
77
vendor.76e65ef421e93d510398.js 493 bytes 1 [emitted] vendor
8-
runtime.js 6.51 kB 2 [emitted] runtime
8+
runtime.js 6.9 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.38 kB 0 [emitted] app
1818
vendor.76e65ef421e93d510398.js 493 bytes 1 [emitted] vendor
19-
runtime.js 6.51 kB 2 [emitted] runtime
19+
runtime.js 6.9 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: 00bdc9e68dab6471776c
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
0.js 149 bytes 0 [emitted]
5-
entry.js 6.54 kB 1 [emitted] entry
5+
entry.js 6.93 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 651 bytes 0 [emitted]
19-
bundle.js 6.44 kB 1 [emitted] main
19+
bundle.js 6.83 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 504 bytes 0 [emitted]
3333
1.bundle.js 232 bytes 1 [emitted]
34-
bundle.js 6.43 kB 2 [emitted] main
34+
bundle.js 6.82 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 232 bytes 0 [emitted]
4949
1.bundle.js 254 bytes 1 [emitted]
5050
2.bundle.js 333 bytes 2 [emitted]
51-
bundle.js 6.42 kB 3 [emitted] main
51+
bundle.js 6.81 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 316 bytes chunk-containing-__a_js [emitted]
55
chunk-containing-__b_js.js 173 bytes chunk-containing-__b_js [emitted]
6-
entry.js 6.32 kB entry [emitted] entry
6+
entry.js 6.7 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: e2a3a4f76d4a30adbf3e
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
entry.js 615 bytes entry [emitted] entry
5-
manifest.js 6.52 kB manifest [emitted] manifest
5+
manifest.js 6.91 kB manifest [emitted] manifest
66
vendor.js 469 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 212 bytes 4, 6 [emitted] chunk
99
5.js 356 bytes 5, 3 [emitted] cir2 from cir1
1010
6.js 130 bytes 6 [emitted] ac in ab
11-
main.js 7.1 kB 7 [emitted] main
11+
main.js 7.49 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)