webpack: Using --bail makes module build errors more cryptic.

We use --bail so that webpack will report errors to our build script (without --bail, it doesn’t give an error exit code).

Unfortunately, when you use --bail, the error result from unparseable JavaScript loses the line that tells you what file the error occurred in.

Example output without --bail:

Hash: 91ed442d775c1a722525
Version: webpack 1.4.13
Time: 3094ms
                                        Asset    Size  Chunks             Chunk Names
<snip>
    + 286 hidden modules

ERROR in ./pages/MyPage.js
Module build failed: Error: Parse Error: Line 7: Unexpected token ;
    at throwError (/Users/sashaaickin/code/main/corvair/node_modules/jsx-loader/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:2644:21)
    at throwUnexpected (/Users/sashaaickin/code/main/corvair/node_modules/jsx-loader/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:2706:9)
<snip>
    at parseProgramElement (/Users/sashaaickin/code/main/corvair/node_modules/jsx-loader/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:6185:16)
 @ ./target-entrypoints/MyPageEntry.js 4:17-68

With --bail, the output looks like:

ModuleBuildError: Module build failed: Error: Parse Error: Line 7: Unexpected token ;
    at throwError (/Users/sashaaickin/code/main/corvair/node_modules/jsx-loader/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:2644:21)
    at throwUnexpected (/Users/sashaaickin/code/main/corvair/node_modules/jsx-loader/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:2706:9)
<snip>
    at /Users/sashaaickin/code/main/corvair/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:270:15
    at runSyncOrAsync (/Users/sashaaickin/code/main/corvair/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:158:12)

Note that without --bail, the file with the syntax error (MyPage.js) is named, but not in the latter. This makes it hard to debug problems that come from our build script, because the error log does not tell us what file the problem is in.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 12
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Any progress about this request? We will never build two times just to improve the logs…