Gracefully handle fatal webpack errors. #1918
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
When a fatal webpack error occurs (e.g. wrong configuration) storybook's error handler incorrectly assumes that the
stats
object is provided by webpack. See https://webpack.js.org/api/node/#error-handling for details on error handling.The effect is the callback throwing an exception at https://github.com/storybooks/storybook/blob/master/app/react/src/server/build.js#L86, with a message to the effect of 'undefined has no property
hasErrors
'.This is a problem because some webpack loaders will run timers or open sockets that prevent the node process from exiting, and when the callback throws an error before reaching the
process.exit(1);
code which would kill it.There have been cases where in continuous integration environments the build will run indefinitely (which is a problem when you pay per-second).
What I did
Added a simple check to ensure
stats
is passed, before using it.How to test
Create a webpack configuration that causes a fatal error, and run storybook.