diff --git a/packages/ngtools/webpack/src/resource_loader.ts b/packages/ngtools/webpack/src/resource_loader.ts index c4d6119a978f..5aa58749223c 100644 --- a/packages/ngtools/webpack/src/resource_loader.ts +++ b/packages/ngtools/webpack/src/resource_loader.ts @@ -275,12 +275,15 @@ export class WebpackResourceLoader { parent.warnings.push(...childCompilation.warnings); parent.errors.push(...childCompilation.errors); - for (const { info, name, source } of childCompilation.getAssets()) { - if (info.sourceFilename === undefined) { - throw new Error(`'${name}' asset info 'sourceFilename' is 'undefined'.`); - } - this.assetCache?.set(info.sourceFilename, { info, name, source }); + if (this.assetCache) { + for (const { info, name, source } of childCompilation.getAssets()) { + // Use the originating file as the cache key if present + // Otherwise, generate a cache key based on the generated name + const cacheKey = info.sourceFilename ?? `!![GENERATED]:${name}`; + + this.assetCache.set(cacheKey, { info, name, source }); + } } }