🐞 Bug report
Command (mark with an x)
Is this a regression?
I don't think so
Description
When you import a third party dependecy that uses private class fields (Native private class features), they end up being inserted into the constructor before the super() call.
🔬 Minimal Reproduction
- Create a new Angular project
- Add a third party library that uses private class fields (
npm install scrollable-component@1.2.0)
- Import the library (
import 'scrollable-component'; inside your main.ts)
- Build the project (
ng build or ng serve --configuration production, optimization should be set to true inside your angular.json)
- The generated code is incorrect
(here is the third party imported file)
🔥 Exception or Error
Uncaught ReferenceError: must call super constructor before using 'this' in derived class constructor
vendor.js
🌍 Your Environment
@angular-devkit/architect 0.1301.3
@angular-devkit/build-angular 13.1.3
@angular-devkit/core 13.1.3
@angular-devkit/schematics 13.1.3
@angular/cli 13.1.3
@schematics/angular 13.1.3
rxjs 7.5.2
typescript 4.5.4
Anything else relevant?
The bug only occurs when your build configuration contains the "optimization": true (or does not contain the "optimization": false) rule, which is the default for the production configuration.
From what I can understand, something like this happens:
// Before optimization
class Test extends HTMLElement {
#privateField;
constructor() {
super();
}
}
// After optimization
class Test extends HTMLElement {
constructor() {
__definePrivateField(this, privateField);
super();
}
}
I found this issue evanw/esbuild#1918 which may be related and tried several options in my tsconfig.json, like:
"target": "esnext"
"module": "esnext"
but I haven't been able to make it work (the problem also occurs with private class methods).
🐞 Bug report
Command (mark with an
x)Is this a regression?
I don't think so
Description
When you import a third party dependecy that uses private class fields (Native private class features), they end up being inserted into the constructor before the
super()call.🔬 Minimal Reproduction
npm install scrollable-component@1.2.0)import 'scrollable-component';inside yourmain.ts)ng buildorng serve --configuration production,optimizationshould be set totrueinside yourangular.json)(here is the third party imported file)
🔥 Exception or Error
🌍 Your Environment
Anything else relevant?
The bug only occurs when your build configuration contains the
"optimization": true(or does not contain the"optimization": false) rule, which is the default for theproductionconfiguration.From what I can understand, something like this happens:
I found this issue evanw/esbuild#1918 which may be related and tried several options in my
tsconfig.json, like:"target": "esnext""module": "esnext"but I haven't been able to make it work (the problem also occurs with private class methods).