Skip to content

Commit 71073a9

Browse files
filipesilvadond2clouds
authored andcommitted
fix(@ngtools/webpack): improve missing TS file error message
Related to angular#8284 (comment)
1 parent 0f73f7a commit 71073a9

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

packages/@ngtools/webpack/src/angular_compiler_plugin.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -816,16 +816,20 @@ export class AngularCompilerPlugin implements Tapable {
816816
.map((p) => this._compilerHost.denormalizePath(p));
817817
}
818818
} else {
819-
// Check if the TS file exists.
820-
if (fileName.endsWith('.ts') && !this._compilerHost.fileExists(fileName, false)) {
821-
throw new Error(`${fileName} is not part of the compilation. `
822-
+ `Please make sure it is in your tsconfig via the 'files' or 'include' property.`);
823-
}
819+
// Check if the TS input file and the JS output file exist.
820+
if ((fileName.endsWith('.ts') && !this._compilerHost.fileExists(fileName, false))
821+
|| !this._compilerHost.fileExists(outputFile, false)) {
822+
let msg = `${fileName} is missing from the TypeScript compilation. `
823+
+ `Please make sure it is in your tsconfig via the 'files' or 'include' property.`;
824+
825+
if (/(\\|\/)node_modules(\\|\/)/.test(fileName)) {
826+
msg += '\nThe missing file seems to be part of a third party library. '
827+
+ 'TS files in published libraries are often a sign of a badly packaged library. '
828+
+ 'Please open an issue in the library repository to alert its author and ask them '
829+
+ 'to package the library using the Angular Package Format (https://goo.gl/jB3GVv).';
830+
}
824831

825-
// Check if the output file exists.
826-
if (!this._compilerHost.fileExists(outputFile, false)) {
827-
throw new Error(`${fileName} is not part of the compilation output. `
828-
+ `Please check the other error messages for details.`);
832+
throw new Error(msg);
829833
}
830834

831835
outputText = this._compilerHost.readFile(outputFile);

tests/e2e/tests/build/build-errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function () {
3939
}))
4040
.then(() => expectToFail(() => ng('build')))
4141
.then(({ message }) => {
42-
if (!message.includes('polyfills.ts is not part of the compilation')) {
42+
if (!message.includes('polyfills.ts is missing from the TypeScript compilation')) {
4343
throw new Error(`Expected missing TS file error, got this instead:\n${message}`);
4444
}
4545
if (extraErrors.some((e) => message.includes(e))) {

0 commit comments

Comments
 (0)