Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Invalid ngDevMode usage in library build output #63677

@mdudek

Description

@mdudek

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

When building an Angular library, the generated JS code contains direct references to ngDevMode inside input() and viewChild() calls.

class TestComponent {
    name = input(...(ngDevMode ? [undefined, { debugName: "name" }] : []));
    myElRef = viewChild('myEl', ...(ngDevMode ? [{ debugName: "myElRef" }] : []));
    // ...
}

This causes a runtime exception in production builds, since ngDevMode is not declared.

Expected Behavior

ngDevMode should be guarded with a safe check, as it is in other parts of Angular’s generated code.
Correct usage should be:

class TestComponent {
    name = input(...((typeof ngDevMode === "undefined" || ngDevMode) ? [undefined, { debugName: "name" }] : []));
    myElRef = viewChild('myEl', ...((typeof ngDevMode === "undefined" || ngDevMode) ? [{ debugName: "myElRef" }] : []));
}

angular-ngdevmode-demo.zip

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Reference error: ngDevMode is not defined

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 20.2.2
Node: 24.6.0
Package Manager: npm 11.5.1
OS: win32 x64


Angular: 20.2.4
... common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                      Version
------------------------------------
@angular-devkit/architect    0.2002.2
@angular-devkit/core         20.2.2
@angular-devkit/schematics   20.2.2
@angular/build               20.2.2
@angular/cli                 20.2.2
@schematics/angular          20.2.2
ng-packagr                   20.2.0
rxjs                         7.8.2
typescript                   5.9.2

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: compilerIssues related to `ngc`, Angular's template compiler

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions