Skip to content

Commit 38bd634

Browse files
committed
Print friendly error
1 parent 1feaa5c commit 38bd634

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ function verifyTypeScriptSetup() {
103103
},
104104
};
105105

106+
const formatDiagnosticHost = {
107+
getCanonicalFileName: fileName => fileName,
108+
getCurrentDirectory: ts.sys.getCurrentDirectory,
109+
getNewLine: () => os.EOL,
110+
};
111+
106112
const messages = [];
107113
let appTsConfig;
108114
let parsedTsConfig;
@@ -114,7 +120,7 @@ function verifyTypeScriptSetup() {
114120
);
115121

116122
if (error) {
117-
throw error;
123+
throw new Error(ts.formatDiagnostic(error, formatDiagnosticHost));
118124
}
119125

120126
appTsConfig = readTsConfig;
@@ -132,18 +138,21 @@ function verifyTypeScriptSetup() {
132138
});
133139

134140
if (result.errors && result.errors.length) {
135-
throw result.errors[0];
141+
throw new Error(
142+
ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)
143+
);
136144
}
137145

138146
parsedCompilerOptions = result.options;
139-
} catch (_) {
147+
} catch (e) {
140148
console.error(
141149
chalk.red.bold(
142150
'Could not parse',
143151
chalk.cyan('tsconfig.json') + '.',
144152
'Please make sure it contains syntactically correct JSON.'
145153
)
146154
);
155+
console.error(e && e.message ? `Details: ${e.message}` : '');
147156
process.exit(1);
148157
}
149158

0 commit comments

Comments
 (0)