diff --git a/packages/@ngtools/webpack/src/plugin.ts b/packages/@ngtools/webpack/src/plugin.ts index b62e26960bd7..86ec478156ff 100644 --- a/packages/@ngtools/webpack/src/plugin.ts +++ b/packages/@ngtools/webpack/src/plugin.ts @@ -113,13 +113,16 @@ export class AotPlugin implements Tapable { basePath = path.resolve(process.cwd(), options.basePath); } - let tsConfigJson: any = null; - try { - tsConfigJson = JSON.parse(ts.sys.readFile(this._tsConfigPath)); - } catch (err) { - throw new Error(`An error happened while parsing ${this._tsConfigPath} JSON: ${err}.`); + const configResult = ts.readConfigFile(this._tsConfigPath, ts.sys.readFile); + if (configResult.error) { + const diagnostic = configResult.error; + const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + throw new Error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message})`); } + const tsConfigJson = configResult.config; + if (options.hasOwnProperty('compilerOptions')) { tsConfigJson.compilerOptions = Object.assign({}, tsConfigJson.compilerOptions, diff --git a/tests/e2e/assets/webpack/test-app/tsconfig.json b/tests/e2e/assets/webpack/test-app/tsconfig.json index cee38681d901..f9ca9f3932a5 100644 --- a/tests/e2e/assets/webpack/test-app/tsconfig.json +++ b/tests/e2e/assets/webpack/test-app/tsconfig.json @@ -1,4 +1,5 @@ { + // Test comment "compilerOptions": { "baseUrl": "", "module": "es2015",