diff --git a/packages/ngtools/webpack/src/resource_loader.ts b/packages/ngtools/webpack/src/resource_loader.ts index c7b8850c7e04..d494cdc930b2 100644 --- a/packages/ngtools/webpack/src/resource_loader.ts +++ b/packages/ngtools/webpack/src/resource_loader.ts @@ -274,12 +274,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 }); + } } }