UNPKG

1.23 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8'use strict';
9
10const chalk = require('chalk');
11
12module.exports = function printBuildError(err) {
13 const message = err != null && err.message;
14 const stack = err != null && err.stack;
15
16 // Add more helpful message for Terser error
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};