-
-
Notifications
You must be signed in to change notification settings - Fork 27k
format UglifyJs error #2650
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
format UglifyJs error #2650
Changes from 1 commit
3641c5c
52bd133
0af70c2
b53f903
31fe07e
212736d
a0d089b
8f67581
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); | |
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); | ||
const printHostingInstructions = require('react-dev-utils/printHostingInstructions'); | ||
const FileSizeReporter = require('react-dev-utils/FileSizeReporter'); | ||
const get = require('lodash/get'); | ||
|
||
const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild; | ||
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild; | ||
|
@@ -93,7 +94,7 @@ measureFileSizesBeforeBuild(paths.appBuild) | |
}, | ||
err => { | ||
console.log(chalk.red('Failed to compile.\n')); | ||
console.log((err.message || err) + '\n'); | ||
formatError(err); | ||
process.exit(1); | ||
} | ||
); | ||
|
@@ -141,3 +142,30 @@ function copyPublicFolder() { | |
filter: file => file !== paths.appHtml, | ||
}); | ||
} | ||
|
||
function formatError(err) { | ||
const message = get(err, 'message'); | ||
|
||
// Add more helpful message for UglifyJs error | ||
if (typeof message === 'string' && message.indexOf('from UglifyJs') !== -1) { | ||
try { | ||
console.log( | ||
'UglifyJs could not parse the code from \n\n', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's say |
||
chalk.yellow( | ||
err.stack.split('\n')[1].split('[')[1].split('][')[0].replace(']', '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer if we checked against a regex (and extracted from it) instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my regex is not very good, the string from
Haven't developed the muscle memory for regexing that 😢 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use https://regex101.com/ for testing regexes. I don't mind split/joining too much either, but then we need to test that it matches the format first somehow. Before we attempt to parse. So that we don't end up with garbage. |
||
), | ||
'\n' | ||
); | ||
} catch (e) { | ||
console.log('UglifyJs could not process the code.', err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's say |
||
} | ||
console.log( | ||
'Please check your dependencies for any untranspiled es6 code and raise an issue with \n' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll want to tweak this message but let's fix other issues first. |
||
'the author. \n' + | ||
'\nIf you need to use the module right now, you can try placing the source in ./src \n' + | ||
'and we will transpile it for you.' | ||
); | ||
} else { | ||
console.log((message || err) + '\n'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to
react-dev-utils
. Something likeformatBuildError
.