1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | const chalk = require('chalk');
|
11 |
|
12 | module.exports = function printBuildError(err) {
|
13 | const message = err != null && err.message;
|
14 | const stack = err != null && err.stack;
|
15 |
|
16 |
|
17 | if (
|
18 | stack &&
|
19 | typeof message === 'string' &&
|
20 | message.indexOf('from Terser') !== -1
|
21 | ) {
|
22 | try {
|
23 | const matched = /(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec(stack);
|
24 | if (!matched) {
|
25 | throw new Error('Using errors for control flow is bad.');
|
26 | }
|
27 | const problemPath = matched[2];
|
28 | const line = matched[3];
|
29 | const column = matched[4];
|
30 | console.log(
|
31 | 'Failed to minify the code from this file: \n\n',
|
32 | chalk.yellow(
|
33 | `\t${problemPath}:${line}${column !== '0' ? ':' + column : ''}`
|
34 | ),
|
35 | '\n'
|
36 | );
|
37 | } catch (ignored) {
|
38 | console.log('Failed to minify the bundle.', err);
|
39 | }
|
40 | console.log('Read more here: https://cra.link/failed-to-minify');
|
41 | } else {
|
42 | console.log((message || err) + '\n');
|
43 | }
|
44 | console.log();
|
45 | };
|