Skip to content

Commit

Permalink
fix(@ngtools/webpack): improve missing TS file error message
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and dond2clouds committed Apr 23, 2018
1 parent 0f73f7a commit 71073a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions packages/@ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/tests/build/build-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down

0 comments on commit 71073a9

Please sign in to comment.