From 71073a9c79b49df990761534e3fb2a5ebea2f96c Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Thu, 21 Dec 2017 19:42:57 +0000 Subject: [PATCH] fix(@ngtools/webpack): improve missing TS file error message Related to https://github.com/angular/angular-cli/issues/8284#issuecomment-341417325 --- .../webpack/src/angular_compiler_plugin.ts | 22 +++++++++++-------- tests/e2e/tests/build/build-errors.ts | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/@ngtools/webpack/src/angular_compiler_plugin.ts b/packages/@ngtools/webpack/src/angular_compiler_plugin.ts index 10bb8819fe81..1c95c4481226 100644 --- a/packages/@ngtools/webpack/src/angular_compiler_plugin.ts +++ b/packages/@ngtools/webpack/src/angular_compiler_plugin.ts @@ -816,16 +816,20 @@ export class AngularCompilerPlugin implements Tapable { .map((p) => this._compilerHost.denormalizePath(p)); } } else { - // Check if the TS file exists. - if (fileName.endsWith('.ts') && !this._compilerHost.fileExists(fileName, false)) { - throw new Error(`${fileName} is not part of the compilation. ` - + `Please make sure it is in your tsconfig via the 'files' or 'include' property.`); - } + // Check if the TS input file and the JS output file exist. + if ((fileName.endsWith('.ts') && !this._compilerHost.fileExists(fileName, false)) + || !this._compilerHost.fileExists(outputFile, false)) { + let msg = `${fileName} is missing from the TypeScript compilation. ` + + `Please make sure it is in your tsconfig via the 'files' or 'include' property.`; + + if (/(\\|\/)node_modules(\\|\/)/.test(fileName)) { + msg += '\nThe missing file seems to be part of a third party library. ' + + 'TS files in published libraries are often a sign of a badly packaged library. ' + + 'Please open an issue in the library repository to alert its author and ask them ' + + 'to package the library using the Angular Package Format (https://goo.gl/jB3GVv).'; + } - // Check if the output file exists. - if (!this._compilerHost.fileExists(outputFile, false)) { - throw new Error(`${fileName} is not part of the compilation output. ` - + `Please check the other error messages for details.`); + throw new Error(msg); } outputText = this._compilerHost.readFile(outputFile); diff --git a/tests/e2e/tests/build/build-errors.ts b/tests/e2e/tests/build/build-errors.ts index 32ce0ff98ddb..a5a97af7fb49 100644 --- a/tests/e2e/tests/build/build-errors.ts +++ b/tests/e2e/tests/build/build-errors.ts @@ -39,7 +39,7 @@ export default function () { })) .then(() => expectToFail(() => ng('build'))) .then(({ message }) => { - if (!message.includes('polyfills.ts is not part of the compilation')) { + if (!message.includes('polyfills.ts is missing from the TypeScript compilation')) { throw new Error(`Expected missing TS file error, got this instead:\n${message}`); } if (extraErrors.some((e) => message.includes(e))) {