@@ -26,6 +26,28 @@ function isLikelyASyntaxError(message) {
26
26
function formatMessage ( message , isError ) {
27
27
var lines = message . split ( '\n' ) ;
28
28
29
+ // Strip `WorkerError` header off message before parsing
30
+ // https://github.com/webpack-contrib/thread-loader/blob/6fb5daff313c4839196cf533bdcdf14815a386d2/src/WorkerError.js
31
+ lines = lines . filter ( function ( message ) {
32
+ return message . indexOf ( 'Thread Loader (Worker' ) === - 1 ;
33
+ } ) ;
34
+
35
+ // Strip `ModuleError` header off message before parsing
36
+ // https://github.com/webpack/webpack/blob/c77030573de96b8293c69dd396492f8e2d46561e/lib/ModuleError.js
37
+ var moduleErrorPrefix = 'Module Error: ' ;
38
+ if ( lines [ 1 ] . indexOf ( moduleErrorPrefix ) === 0 ) {
39
+ lines [ 1 ] = lines [ 1 ] . slice ( moduleErrorPrefix . length ) ;
40
+ } else if ( lines [ 1 ] . match ( / M o d u l e E r r o r \( f r o m .* ?\) : / ) ) {
41
+ lines . splice ( 1 , 1 ) ;
42
+ }
43
+
44
+ // Simplify `ModuleBuildError` before parsing
45
+ // https://github.com/webpack/webpack/blob/c77030573de96b8293c69dd396492f8e2d46561e/lib/ModuleBuildError.js
46
+ if ( lines [ 1 ] . match ( / M o d u l e b u i l d f a i l e d \( f r o m .* ?\) : / ) ) {
47
+ lines . splice ( 1 , 1 ) ;
48
+ lines [ 1 ] = 'Module build failed: ' + lines [ 1 ] ;
49
+ }
50
+
29
51
if ( lines . length > 2 && lines [ 1 ] === '' ) {
30
52
// Remove extra newline.
31
53
lines . splice ( 1 , 1 ) ;
@@ -40,21 +62,6 @@ function formatMessage(message, isError) {
40
62
lines [ 0 ] = lines [ 0 ] . substr ( lines [ 0 ] . lastIndexOf ( '!' ) + 1 ) ;
41
63
}
42
64
43
- // Remove unnecessary stack added by `thread-loader`
44
- var threadLoaderIndex = - 1 ;
45
- lines . forEach ( function ( line , index ) {
46
- if ( threadLoaderIndex !== - 1 ) {
47
- return ;
48
- }
49
- if ( / t h r e a d .l o a d e r / i. test ( line ) ) {
50
- threadLoaderIndex = index ;
51
- }
52
- } ) ;
53
-
54
- if ( threadLoaderIndex !== - 1 ) {
55
- lines = lines . slice ( 0 , threadLoaderIndex ) ;
56
- }
57
-
58
65
lines = lines . filter ( function ( line ) {
59
66
// Webpack adds a list of entry points to warning messages:
60
67
// @ ./src/index.js
@@ -86,8 +93,8 @@ function formatMessage(message, isError) {
86
93
// Cleans up syntax error messages.
87
94
if ( lines [ 1 ] . indexOf ( 'Module build failed: ' ) === 0 ) {
88
95
lines [ 1 ] = lines [ 1 ] . replace (
89
- ' Module build failed: SyntaxError:' ,
90
- friendlySyntaxErrorLabel
96
+ / M o d u l e b u i l d f a i l e d : . * ? : / ,
97
+ friendlySyntaxErrorLabel + ' '
91
98
) ;
92
99
}
93
100
0 commit comments