Skip to content

Commit 5b9284b

Browse files
johann-sonntagbauergaearon
authored andcommitted
(feat): add webpack validation error logging (facebook#1596)
* (feat): add webpack validation error logging * Style nit * Style tweak * Style nit
1 parent 37e1d64 commit 5b9284b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/react-scripts/scripts/build.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,16 @@ function printErrors(summary, errors) {
133133
// Create the production build and print the deployment instructions.
134134
function build(previousSizeMap) {
135135
console.log('Creating an optimized production build...');
136-
webpack(config).run((err, stats) => {
136+
137+
var compiler;
138+
try {
139+
compiler = webpack(config);
140+
} catch (err) {
141+
printErrors('Failed to compile.', [err]);
142+
process.exit(1);
143+
}
144+
145+
compiler.run((err, stats) => {
137146
if (err) {
138147
printErrors('Failed to compile.', [err]);
139148
process.exit(1);

packages/react-scripts/scripts/start.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ if (isSmokeTest) {
6363
function setupCompiler(host, port, protocol) {
6464
// "Compiler" is a low-level interface to Webpack.
6565
// It lets us listen to some events and provide our own custom messages.
66-
compiler = webpack(config, handleCompile);
66+
try {
67+
compiler = webpack(config, handleCompile);
68+
} catch (err) {
69+
console.log(chalk.red('Failed to compile.'));
70+
console.log();
71+
console.log(err.message || err);
72+
console.log();
73+
process.exit(1);
74+
}
6775

6876
// "invalid" event fires when you have changed a file, and Webpack is
6977
// recompiling a bundle. WebpackDevServer takes care to pause serving the

0 commit comments

Comments
 (0)