-
-
Notifications
You must be signed in to change notification settings - Fork 27k
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 7 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) { | |
}); | ||
``` | ||
|
||
#### `printBuildError(error: Object): String` | ||
|
||
Prettify some known build errors. | ||
Pass an Error object to log a prettified error message in the console | ||
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: missing period at end |
||
|
||
``` | ||
const printBuildError = require('react-dev-utils/printBuildError') | ||
try { | ||
build() | ||
} catch(e) { | ||
printBuildError(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,52 @@ | ||
/** | ||
* 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 printBuildError(err) { | ||
const message = get(err, 'message'); | ||
const stack = get(err, 'stack'); | ||
|
||
// Add more helpful message for UglifyJs error | ||
if ( | ||
stack && | ||
typeof message === 'string' && | ||
message.indexOf('from UglifyJs') !== -1 | ||
) { | ||
try { | ||
const matched = /Unexpected token:(.+)\[(.+)\:(.+)\,(.+)\]\[.+\]/.exec( | ||
stack | ||
); | ||
if (!matched) { | ||
throw new Error( | ||
"The regex pattern is not matched. Maybe UglifyJs changed it's message?" | ||
); | ||
} | ||
const problemPath = matched[2]; | ||
const line = matched[3]; | ||
const column = matched[4]; | ||
console.log( | ||
'Failed to minify the code from this file: \n\n', | ||
chalk.yellow(`${problemPath} line ${line}:${column}`), | ||
'\n' | ||
); | ||
} catch (ignored) { | ||
console.log('Failed to minify the code.', err); | ||
} | ||
console.log('Read more here:'); | ||
console.log( | ||
'https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify\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 shorten this: http://bit.ly/2tRViJ9 |
||
); | ||
} else { | ||
console.log((message || err) + '\n'); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ You can find the most recent version of this guide [here](https://github.com/fac | |
- [`npm test` hangs on macOS Sierra](#npm-test-hangs-on-macos-sierra) | ||
- [`npm run build` exits too early](#npm-run-build-exits-too-early) | ||
- [`npm run build` fails on Heroku](#npm-run-build-fails-on-heroku) | ||
- [`npm run build` fails to minify](#npm-run-build-fails-to-minify) | ||
- [Moment.js locales are missing](#momentjs-locales-are-missing) | ||
- [Something Missing?](#something-missing) | ||
|
||
|
@@ -1998,6 +1999,16 @@ moment.locale('fr'); | |
|
||
This will only work for locales that have been explicitly imported before. | ||
|
||
### `npm run build` fails to minify | ||
|
||
Some dependencies may be shipping their source which our minify can't process. | ||
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 simplify this for now:
|
||
Because running Babel on `node_modules` is slow, we cannot compile it to es5 | ||
before minifying it. Possible solutions are: | ||
1. Raise an issue with the library author to ship compiled es5. | ||
2. If it's small and compatible with out babel preset, you can place the | ||
source in ./src. | ||
3. Fork the project repo and publish an es5 version of it. | ||
|
||
## Something Missing? | ||
|
||
If you have ideas for more “How To” recipes that should be on this page, [let us know](https://github.com/facebookincubator/create-react-app/issues) or [contribute some!](https://github.com/facebookincubator/create-react-app/edit/master/packages/react-scripts/template/README.md) |
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.
I assume this should return
void
.