From 38bd6342ac135b94683b7689db392bca112bc66a Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Tue, 23 Oct 2018 15:32:59 -0400 Subject: [PATCH] Print friendly error --- .../scripts/utils/verifyTypeScriptSetup.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js index fccf657c9d6..50491825da3 100644 --- a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js +++ b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js @@ -103,6 +103,12 @@ function verifyTypeScriptSetup() { }, }; + const formatDiagnosticHost = { + getCanonicalFileName: fileName => fileName, + getCurrentDirectory: ts.sys.getCurrentDirectory, + getNewLine: () => os.EOL, + }; + const messages = []; let appTsConfig; let parsedTsConfig; @@ -114,7 +120,7 @@ function verifyTypeScriptSetup() { ); if (error) { - throw error; + throw new Error(ts.formatDiagnostic(error, formatDiagnosticHost)); } appTsConfig = readTsConfig; @@ -132,11 +138,13 @@ function verifyTypeScriptSetup() { }); if (result.errors && result.errors.length) { - throw result.errors[0]; + throw new Error( + ts.formatDiagnostic(result.errors[0], formatDiagnosticHost) + ); } parsedCompilerOptions = result.options; - } catch (_) { + } catch (e) { console.error( chalk.red.bold( 'Could not parse', @@ -144,6 +152,7 @@ function verifyTypeScriptSetup() { 'Please make sure it contains syntactically correct JSON.' ) ); + console.error(e && e.message ? `Details: ${e.message}` : ''); process.exit(1); }