Repository navigation
Closed
Labels
Milestone
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
When using the @defer block with a component that is exported under an alias, Angular throws an error:
ERROR TypeError: Cannot read properties of undefined (reading 'ɵcmp')
If the same component is used under its original name, everything works as expected.
@Component({
...
})
export class CounterComponent {}// ✅ Works fine when exported original name
// export { CounterComponent } from './counter.component';
// ❌ Fails when exported under an alias
export { CounterComponent as MyCounterCmp } from './counter.component';// ✅ Works fine when imported as original name
// import { CounterComponent } from './counter';
// ❌ Fails when imported alias MyCounterCmp
import { MyCounterCmp } from './counter';
@Component({
...
template: `
@defer {
<my-counter-cmp />
}
`,
imports: [MyCounterCmp],
})Please provide a link to a minimal reproduction of the bug
Please provide the exception or error you saw
ERROR TypeError: Cannot read properties of undefined (reading 'ɵcmp')
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 20.3.2
Node: 20.19.1
Package Manager: npm 10.8.2
OS: linux x64
Angular: 20.3.1
... common, compiler, compiler-cli, core, platform-browser
... platform-server
Package Version
------------------------------------
@angular-devkit/architect 0.2003.2
@angular-devkit/core 20.3.2
@angular-devkit/schematics 20.3.2
@angular/build 20.3.2
@angular/cli 20.3.2
@angular/ssr 20.3.2
@schematics/angular 20.3.2
rxjs 7.8.2
typescript 5.9.2
Anything else?
I used the --no-hmr flag in StackBlitz to prevent deferred block dependencies from being loaded eagerly. With HMR enabled, Angular forces all @defer dependencies to load immediately, which defeats the purpose of testing their lazy behavior.
Reacted by Dmitriy Stepanenko, Dawid Kostka, Jaime Burgos, Adam Bartoszko and miloszrutkowskiHOA
Activity
SkyZeroZx commentedon Sep 20, 2025
I reviewed the code and debugged the core logic related to defer instructions (specifically those tied to the IDLE state).
From the investigation:
The dependenciesFn() generated during compiler parsing of defer blocks does not resolve the correct reference.
As a result, the trigger fails and an unexpected error is thrown.
While debugging further in my node_modules, I found that the issue might be related to the compiler function compileComponentMetadataAsyncResolver.
By adding console.log statements, I was able to trace the file path, but it seems the problem could be tied to a missing or incorrect case when handling renamed files in the index.ts with some alias to components (or a similar mapping). This might explain why the reference fails to resolve properly.
EDIT :
Possible need some parsing to alias in compiler cli
resolveAllDeferredDependenciesin classComponentDecoratorHandlerSkyZeroZx commentedon Sep 20, 2025
I think I’ve fixed the behavior. The issue required some changes in the compiler CLI to correctly parse the data. I tested a local fix by modifying the ComponentDecoratorHandler function, specifically in resolveAllDeferredDependencies, to properly resolve the import information. With this adjustment, the error is resolved.
I’ll continue working to propose this fix.
thePunderWoman commentedon Sep 22, 2025
Closing since #63966 has been merged.
angular-automatic-lock-bot commentedon Oct 23, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.