-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle undefined webpack build error #2360
Conversation
Huh, seems right @jquense, look good? I'm not super familiar with this stuff. Here's a good breakdown of the differences https://stackoverflow.com/questions/40201468/what-constitutes-a-build-error-vs-stats-compilation-errors-or-stats-compilation Looks like we should print both of them out if they exist? |
@iv-mexx could you modify your PR to print out both errors? |
@KyleAMathews I'm not sure what you mean with "both errors". If I understand correctly, the Stackoverflow question you linked talks about the difference between the error returned from webpack in the callback and the error contained in The first one is already handled in the lines above my change (Line 29). If you're talking about the fact, that only |
Using the stats object is the recommended approach by webpack, why not continue to use it but filter out undefined errors in the array? |
@jquense Thats what this PR is doing |
In some cases, `stats.compilation.errors` contains an `undefined`. In these cases, `toJson` crashes when accessing a method on this undefined object. This change now filters out `undefined` errors
Deploy preview failed. Built with commit 2b224fe https://app.netlify.com/sites/using-glamor/deploys/59e506260b79b778ae9607cf |
Deploy preview ready! Built with commit 2b224fe |
Well let's give this a go then :-) |
I ran into this problem when
gatsby build
failed withTypeError: Cannot read property 'chunk' of undefined
After some digging around I found that this was not the actual build error!
For some reason,
stats.compilation.errors
contained anundefined
at first place:stats.compilation.errors
(Not sure where this
undefined
is coming from and it might still bite my ass when I fix the other errors later).This
undefined
caused theTypeError: Cannot read property 'chunk' of undefined
error when callingstats.toJson
and because of that, my actual errors were swallowed, leaving me scratching my head.This proposed change filters out
undefined
fromstats.compilation.errors
before handing the first error to the rejection.I'm not sure why
toJson()
is/was necessary at all since it works right now without.