@@ -41,9 +41,12 @@ function formatMessage(message, isError) {
41
41
lines . splice ( 1 , 1 ) ;
42
42
}
43
43
44
- // Simplify `ModuleBuildError` before parsing
44
+ // Simplify `ModuleBuildError` before parsing (these may be nested so we use a while loop)
45
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 .* ?\) : / ) ) {
46
+ while (
47
+ lines . length > 2 &&
48
+ lines [ 1 ] . match ( / M o d u l e b u i l d f a i l e d \( f r o m .* ?\) : / )
49
+ ) {
47
50
lines . splice ( 1 , 1 ) ;
48
51
lines [ 1 ] = 'Module build failed: ' + lines [ 1 ] ;
49
52
}
@@ -92,10 +95,23 @@ function formatMessage(message, isError) {
92
95
93
96
// Cleans up syntax error messages.
94
97
if ( lines [ 1 ] . indexOf ( 'Module build failed: ' ) === 0 ) {
98
+ lines [ 1 ] = lines [ 1 ] . replace (
99
+ 'Module build failed: Syntax Error ' ,
100
+ friendlySyntaxErrorLabel
101
+ ) ;
95
102
lines [ 1 ] = lines [ 1 ] . replace (
96
103
/ M o d u l e b u i l d f a i l e d : .* ?: / ,
97
104
friendlySyntaxErrorLabel + ' '
98
105
) ;
106
+ lines [ 1 ] = lines [ 1 ] . trim ( ) ;
107
+
108
+ if ( lines [ 1 ] === friendlySyntaxErrorLabel && lines [ 2 ] === '' ) {
109
+ lines . splice ( 2 , 1 ) ;
110
+ if ( lines . length > 2 ) {
111
+ lines [ 1 ] += ' ' + lines [ 2 ] ;
112
+ lines . splice ( 2 , 1 ) ;
113
+ }
114
+ }
99
115
}
100
116
101
117
// Clean up export errors.
@@ -120,6 +136,7 @@ function formatMessage(message, isError) {
120
136
/ ^ \s * a t \s ( (? ! w e b p a c k : ) .) * : \d + : \d + [ \s ) ] * ( \n | $ ) / gm,
121
137
''
122
138
) ; // at ... ...:x:y
139
+ message = message . replace ( / ^ \s * a t \s < a n o n y m o u s > ( \n | $ ) / gm, '' ) ; // at <anonymous>
123
140
124
141
return message . trim ( ) ;
125
142
}
0 commit comments