Skip to content

Commit 6d909ca

Browse files
authored
Polish webpack message output (facebook#5174)
* Only install react-scripts in CI mode * Link locally * Re-enable all output tests * 💄 Polish webpack output * Test sass support message * Add more tests, but disabled * Format missing default export error * Format aliased import * Why was node-sass required? Odd * Format webpack rejection error * Re-enable unknown package test * Format file not found error and catch module scope plugin error * Re-disable case sensitive paths * Intercept and format case sensitive path errors * Test out of scope message formatting * Run behavior on macOS * Run behavior on Node 8 and 10, only Node 8 for macOS * Add some debugging * Update matcher * Only check stderr * Remove old snapshot * More debug * Remove debug * Add new debug * Disable test on linux * Add comment for future
1 parent f8e2167 commit 6d909ca

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

config/webpack.config.dev.js

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const getClientEnvironment = require('./env');
2020
const paths = require('./paths');
2121
const ManifestPlugin = require('webpack-manifest-plugin');
2222
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
23+
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
2324

2425
// Webpack uses `publicPath` to determine where the app is being served from.
2526
// In development, we always serve from the root. This makes config easier.
@@ -372,6 +373,9 @@ module.exports = {
372373
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
373374
// In development, this will be an empty string.
374375
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
376+
// This gives some necessary context to module not found errors, such as
377+
// the requesting resource.
378+
new ModuleNotFoundPlugin(paths.appPath),
375379
// Makes some environment variables available to the JS code, for example:
376380
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
377381
new webpack.DefinePlugin(env.stringified),

config/webpack.config.prod.js

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent')
2424
const paths = require('./paths');
2525
const getClientEnvironment = require('./env');
2626
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
27+
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
2728

2829
// Webpack uses `publicPath` to determine where the app is being served from.
2930
// It requires a trailing slash, or the file assets will get an incorrect path.
@@ -459,6 +460,9 @@ module.exports = {
459460
// In production, it will be an empty string unless you specify "homepage"
460461
// in `package.json`, in which case it will be the pathname of that URL.
461462
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
463+
// This gives some necessary context to module not found errors, such as
464+
// the requesting resource.
465+
new ModuleNotFoundPlugin(paths.appPath),
462466
// Makes some environment variables available to the JS code, for example:
463467
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
464468
// It is absolutely essential that NODE_ENV was set to production here.

scripts/build.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,20 @@ function build(previousFileSizes) {
141141
let compiler = webpack(config);
142142
return new Promise((resolve, reject) => {
143143
compiler.run((err, stats) => {
144+
let messages;
144145
if (err) {
145-
return reject(err);
146+
if (!err.message) {
147+
return reject(err);
148+
}
149+
messages = formatWebpackMessages({
150+
errors: [err.message],
151+
warnings: [],
152+
});
153+
} else {
154+
messages = formatWebpackMessages(
155+
stats.toJson({ all: false, warnings: true, errors: true })
156+
);
146157
}
147-
const messages = formatWebpackMessages(
148-
stats.toJson({ all: false, warnings: true, errors: true })
149-
);
150158
if (messages.errors.length) {
151159
// Only keep the first error. Others are often indicative
152160
// of the same problem, but confuse the reader with noise.

0 commit comments

Comments
 (0)