Skip to content

Commit 7d8482d

Browse files
committed
Remove the "Module Build Failed" message from babel SyntaxErrors
1 parent 07fd284 commit 7d8482d

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

src/formatters/moduleNotFound.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
const concat = require('../utils').concat;
23

34
function dependenciesNotFound (count) {
45
if (count === 1) {
@@ -21,12 +22,13 @@ function formatErrors (errors) {
2122
return [];
2223
}
2324

24-
return [
25+
return concat(
2526
dependenciesNotFound(errors.length),
26-
''
27-
]
28-
.concat(errors.map(e =>`* ${e.module}`))
29-
.concat('', forgetToInstall(errors.length));
27+
'',
28+
errors.map(e =>`* ${e.module}`),
29+
'',
30+
forgetToInstall(errors.length)
31+
);
3032
}
3133

3234
function format (errors) {

src/friendly-errors-plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class FriendlyErrorsWebpackPlugin {
8989
output.title(severity, severity.toUpperCase(), subtitle);
9090

9191
if (this.onErrors) {
92-
this.onErrors(severity, processedErrors);
92+
this.onErrors(severity, topErrors);
9393
}
9494

9595
formatErrors(topErrors, this.formatters, severity)

src/transformers/babelSyntax.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
'use strict';
22

3+
/**
4+
* This will be removed in next versions as it is not handled in the babel-loader
5+
* See: https://github.com/geowarin/friendly-errors-webpack-plugin/issues/2
6+
*/
37
function cleanStackTrace(message) {
48
return message
59
.replace(/^\s*at\s.*:\d+:\d+[\s\)]*\n/gm, ''); // at ... ...:x:y
610
}
711

12+
function cleanMessage(message) {
13+
return message
14+
.replace('Module build failed: ', '');
15+
}
16+
817
function isBabelSyntaxError(e) {
918
return e.name === 'ModuleBuildError' &&
1019
e.message.indexOf('SyntaxError') >= 0;
@@ -13,7 +22,7 @@ function isBabelSyntaxError(e) {
1322
function transform(error) {
1423
if (isBabelSyntaxError(error)) {
1524
return Object.assign({}, error, {
16-
message: cleanStackTrace(error.message + '\n'),
25+
message: cleanStackTrace(cleanMessage(error.message) + '\n'),
1726
severity: 1000,
1827
});
1928
}

test/integration.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test('integration : babel syntax error', t => {
5757
'',
5858
' error in ./fixtures/babel-syntax/index.js',
5959
'',
60-
`Module build failed: SyntaxError: Unexpected token (5:11)
60+
`SyntaxError: Unexpected token (5:11)
6161
6262
3 |${' '}
6363
4 | render() {

0 commit comments

Comments
 (0)