Skip to content

Commit 710557f

Browse files
committed
Fix syntax error message massaging
1 parent 22353ec commit 710557f

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

packages/react-dev-utils/formatWebpackMessages.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ function isLikelyASyntaxError(message) {
2626
function formatMessage(message, isError) {
2727
var lines = message.split('\n');
2828

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(/Module Error \(from.*?\):/)) {
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(/Module build failed \(from.*?\):/)) {
47+
lines.splice(1, 1);
48+
lines[1] = 'Module build failed: ' + lines[1];
49+
}
50+
2951
if (lines.length > 2 && lines[1] === '') {
3052
// Remove extra newline.
3153
lines.splice(1, 1);
@@ -40,21 +62,6 @@ function formatMessage(message, isError) {
4062
lines[0] = lines[0].substr(lines[0].lastIndexOf('!') + 1);
4163
}
4264

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 (/thread.loader/i.test(line)) {
50-
threadLoaderIndex = index;
51-
}
52-
});
53-
54-
if (threadLoaderIndex !== -1) {
55-
lines = lines.slice(0, threadLoaderIndex);
56-
}
57-
5865
lines = lines.filter(function(line) {
5966
// Webpack adds a list of entry points to warning messages:
6067
// @ ./src/index.js
@@ -86,8 +93,8 @@ function formatMessage(message, isError) {
8693
// Cleans up syntax error messages.
8794
if (lines[1].indexOf('Module build failed: ') === 0) {
8895
lines[1] = lines[1].replace(
89-
'Module build failed: SyntaxError:',
90-
friendlySyntaxErrorLabel
96+
/Module build failed: .*?: /,
97+
friendlySyntaxErrorLabel + ' '
9198
);
9299
}
93100

0 commit comments

Comments
 (0)