-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
format UglifyJs error #2650
Changes from 4 commits
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 |
---|---|---|
|
@@ -220,6 +220,20 @@ compiler.plugin('done', function(stats) { | |
}); | ||
``` | ||
|
||
#### `formatBuildError(error: Object): String` | ||
|
||
Prettify some known build errors. | ||
Pass an Error object to log a prettified error message in the console | ||
|
||
``` | ||
const formatBuildError = require('react-dev-utils/formatBuildError') | ||
try { | ||
build() | ||
} catch(e){ | ||
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. nit: add missing space |
||
formatBuildError(e) // logs prettified message | ||
} | ||
``` | ||
|
||
#### `getProcessForPort(port: number): string` | ||
|
||
Finds the currently running process on `port`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const get = require('lodash/get'); | ||
const chalk = require('chalk'); | ||
|
||
module.exports = function formatBuildError(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. I'm really not fond of this name since it does more than just formatting the error message. 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. any suggestion? haven't got anything better pops up... 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. How about |
||
const message = get(err, 'message'); | ||
|
||
// Add more helpful message for UglifyJs error | ||
if (typeof message === 'string' && message.indexOf('from UglifyJs') !== -1) { | ||
try { | ||
console.log( | ||
'Failed to minify 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. How about a colon? |
||
chalk.yellow( | ||
/Unexpected token:(.+)\[(.+)\]\[(.+)\]/.exec(err.stack)[2] | ||
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. This could not match or be undefined (in the future if the text format changes); we probably shouldn't assume it's always going to be OK (we don't want this method throwing an error). 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. Also, I don't think I really like how the line / col is shown -- can we make this more human readable? 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. |
||
), | ||
'\n' | ||
); | ||
} catch (e) { | ||
console.log('Failed to minify the code.', err); | ||
} | ||
console.log( | ||
'Please check your dependencies for any untranspiled es6 code and raise an issue with \n' + | ||
'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.' | ||
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'm not a huge fan of this message. Can we add an entry for this into the User Guide and link to it instead? |
||
); | ||
} 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.
nit: missing period at end