Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorator metadata missing in production build #28155

Open
bagbag opened this issue Aug 3, 2024 · 5 comments
Open

Decorator metadata missing in production build #28155

bagbag opened this issue Aug 3, 2024 · 5 comments

Comments

@bagbag
Copy link

bagbag commented Aug 3, 2024

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

compiler-cli, compiler

Is this a regression?

Yes

Description

Decorator metadata like "design:type" is missing in production builds, while working in development.

Having the following code:

export class MyClass {
  @Property()
  address: string;
}

Compiles the to the following in development:

var MyClass = class {
}
;
__decorate20([Property16(), __metadata20("design:type", String)], MyClass.prototype, "address", void 0);

But to the following in production build:

var Nr = class {
}
;
r([t()], Nr.prototype, "address", 2),

The information about the property address being of type String is missing.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

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

Angular CLI: 18.1.3
Node: 22.5.1
Package Manager: npm 10.8.2
OS: linux x64

Angular: 18.1.3
... animations, build, cdk, cli, common, compiler, compiler-cli
... core, forms, platform-browser, platform-browser-dynamic
... router, service-worker

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1801.3
@angular-devkit/core         18.1.3
@angular-devkit/schematics   18.1.3
@schematics/angular          18.1.3
rxjs                         7.8.1
typescript                   5.5.4

Anything else?

No response

@JeanMeche
Copy link
Member

Hi, could you provide a stackblitz repro or a github repo that exhibits this issue ?

@JoostK JoostK transferred this issue from angular/angular Aug 3, 2024
@bagbag
Copy link
Author

bagbag commented Aug 4, 2024

I've created a minimal reproduction: https://github.com/bagbag/angular-decorator-metadata

If you start the application with ng serve, you will see Design type: String
If you start the application with ng serve --configuration production, you will see Could not get design type, as the decorator metadata is not added to the compiled output.

While trying to reproduce this problem I found out, that it only occurs if isolatedModules is set to true in tsconfig.

@JeanMeche
Copy link
Member

It looks like to be linked to #27752.

Esbuild doesn't generate those metadata.

@JoostK
Copy link
Member

JoostK commented Aug 4, 2024

It looks like to be linked to #27752.

Esbuild doesn't generate those metadata.

Yeah, I suppose the CLI should not use this mode when emitDecoratorMetadata is enabled.

That said, I wouldn't want to depend on this metadata going forward, as it's currently only supported for the experimental decorators in TS, not the ES standard ones. reference

@clydin
Copy link
Member

clydin commented Aug 5, 2024

Additionally, emitDecoratorMetadata itself has design flaws that can cause it to generate runtime TDZ errors in ES2015+ code. All code generated by the Angular CLI is ES2015+. Angular does not require the use of the option and unless absolutely required by specific project code, the option should ideally be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants