diff --git a/modules/@angular/compiler-cli/src/codegen.ts b/modules/@angular/compiler-cli/src/codegen.ts index 85e2ab5901..950086bfa7 100644 --- a/modules/@angular/compiler-cli/src/codegen.ts +++ b/modules/@angular/compiler-cli/src/codegen.ts @@ -131,7 +131,15 @@ export class CodeGenerator { static create( options: AngularCompilerOptions, program: ts.Program, compilerHost: ts.CompilerHost, reflectorHostContext?: ReflectorHostContext): CodeGenerator { - const xhr: compiler.XHR = {get: (s: string) => Promise.resolve(compilerHost.readFile(s))}; + const xhr: compiler.XHR = { + get: (s: string) => { + if (!compilerHost.fileExists(s)) { + // TODO: We should really have a test for error cases like this! + throw new Error(`Compilation failed. Resource file not found: ${s}`); + } + return Promise.resolve(compilerHost.readFile(s)); + } + }; const urlResolver: compiler.UrlResolver = compiler.createOfflineCompileUrlResolver(); const reflectorHost = new ReflectorHost(program, compilerHost, options, reflectorHostContext); const staticReflector = new StaticReflector(reflectorHost); diff --git a/modules/@angular/compiler-cli/src/extract_i18n.ts b/modules/@angular/compiler-cli/src/extract_i18n.ts index 6c8dbec307..8106f8ccb0 100644 --- a/modules/@angular/compiler-cli/src/extract_i18n.ts +++ b/modules/@angular/compiler-cli/src/extract_i18n.ts @@ -141,7 +141,15 @@ class Extractor { static create( options: tsc.AngularCompilerOptions, program: ts.Program, compilerHost: ts.CompilerHost): Extractor { - const xhr: compiler.XHR = {get: (s: string) => Promise.resolve(compilerHost.readFile(s))}; + const xhr: compiler.XHR = { + get: (s: string) => { + if (!compilerHost.fileExists(s)) { + // TODO: We should really have a test for error cases like this! + throw new Error(`Compilation failed. Resource file not found: ${s}`); + } + return Promise.resolve(compilerHost.readFile(s)); + } + }; const urlResolver: compiler.UrlResolver = compiler.createOfflineCompileUrlResolver(); const reflectorHost = new ReflectorHost(program, compilerHost, options); const staticReflector = new StaticReflector(reflectorHost);