Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Named class expression extending import-aliased class does not compile correctly with @angular/build:application #31052

Closed as not planned
@dmp-gottschalk

Description

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When extending a class, which was imported and aliased, in a class expression, using the same name, there will be a name clash after building with "optimization": false.
This will throw a ReferenceError: Cannot access 'ClassName' before initialization at runtime, every time the class expression gets executed.
I do not know for sure, if this ever worked. But I think it did, sadly I can not say in which version. Probably with a different builder than @angular/build:application.

Minimal Reproduction

Running ng build with "optimization": false on the following file:

import { MyService as RealMyService } from './my-service';
export const factory = () => new (class MyService extends RealMyService { })

This will result in a compilation output of:

var factory = () => new class MyService extends MyService {
}
();

Minimal reproducer: https://github.com/dmp-gottschalk/angular-karma-build-alias-reproducer/

Exception or Error

ERROR ReferenceError: Cannot access 'MyService' before initialization
 at factory (factory.ts:3:59)
 at _App.makeServiceDoStuff (app.ts:16:5)
 at App_Template_button_click_39_listener (app.html:343:18)
 at executeListenerWithErrorHandling (debug_node.mjs:12982:16)
 at wrapListenerIn_markDirtyAndPreventDefault (debug_node.mjs:12965:22)
 at HTMLButtonElement.<anonymous> (dom_renderer.mjs:736:142)
 at _ZoneDelegate.invokeTask (zone.js:431:33)
 at debug_node.mjs:16349:55
 at AsyncStackTaggingZoneSpec.onInvokeTask (debug_node.mjs:16349:36)
 at _ZoneDelegate.invokeTask (zone.js:430:38)

Your Environment

_ _ ____ _ ___
 / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
 / しろさんかく \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
 / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
 /_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
 |___/
 
Angular CLI: 20.2.0
Node: 24.2.0
Package Manager: npm 11.5.2
OS: linux x64
 
Angular: 20.2.1
... common, compiler, compiler-cli, core, forms
... platform-browser, router
Package Version
------------------------------------
@angular-devkit/architect 0.2002.0
@angular-devkit/core 20.2.0
@angular-devkit/schematics 20.2.0
@angular/build 20.2.0
@angular/cli 20.2.0
@schematics/angular 20.2.0
rxjs 7.8.2
typescript 5.9.2
zone.js 0.15.1

Anything else relevant?

Because build is affected, commands using that (eg serve, test) are also affected

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /