diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index b62fb3b638ff1..a4541a75039db 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -2047,7 +2047,20 @@ export function readJsonConfigFile(fileName: string, readFile: (path: string) => export function tryReadFile(fileName: string, readFile: (path: string) => string | undefined): string | Diagnostic { let text: string | undefined; try { - text = readFile(fileName); + if (fileName.slice(-3) === ".js") { + try { + text = JSON.stringify(require(combinePaths(process.cwd(), fileName))); + } + catch (err) { + return createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, err); + } + } + else if (fileName.slice(-5) === ".json") { + text = readFile(fileName); + } + else { + return createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, "Config file extension is neither .js nor .json"); + } } catch (e) { return createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message);