-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Angular 8 build contains ctorParameters #15404
Comments
I've have a further look into the problem, and compared the previous Angular 7 build with the new Angular 8 build. The interesting thing is that the new build contains a chunk of code that was NOT present in the Angular 7 build: Angular 8 (bad): var A4Action = /** @class */ (function () {
function A4Action(a4Service, a4PatientService) {
var _this = this;
this.a4Service = a4Service;
this.a4PatientService = a4PatientService;
}
A4Action.ctorParameters = function () { return [
{ type: _a4_service__WEBPACK_IMPORTED_MODULE_3__["A4Service"] },
{ type: _a4_patient_service__WEBPACK_IMPORTED_MODULE_4__["A4PatientService"] }
]; };
return A4Action;
}()); Angular 7 (good): var A4Action = /** @class */ (function () {
function A4Action(a4Service, a4PatientService) {
var _this = this;
this.a4Service = a4Service;
this.a4PatientService = a4PatientService;
}
return A4Action;
}()); So it's actually creating a circular dependency where there was none before... Why has this been done? It breaks a lot of code. I feel like there's something I'm missing, maybe a compiler setting or something? Possibly of note Short story: A4Action.ctorParameters = function () { return [
{ type: _a4_service__WEBPACK_IMPORTED_MODULE_3__["A4Service"] },
{ type: _a4_patient_service__WEBPACK_IMPORTED_MODULE_4__["A4PatientService"] }
]; }; Angular 7 build contains no instances of |
Ah I was hoping someone would've taken a look at this by now. Just in case this is related (sounds like it is), I found this:
|
Does the Also, the scrub file optimization pass is not actually related. |
@clydin Thank you for the reply :) A4Action is just a normal class: export class A4Action { } I just did a test - I made a brand new cli project (latest version)... added in a plain class, and a service, and instantly the ng build fails with circular dependencies - because it's including the ctorParameters things in the dist files. Again, this does not happen in Angular 7 builds. import { Injectable } from "@angular/core";
import { MyThing } from './my-thing';
@Injectable()
export class MyService {
myThing = new MyThing(this);
constructor() { }
} import { MyService } from './my.service';
export class MyThing {
seven: number = 7;
constructor(private myService: MyService) { }
} @Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'test';
constructor(myService: MyService) {
console.log(myService.myThing.seven);
}
}
|
This is a bug where This has the effect of converting type-position dependencies into runtime dependencies in arbitrary classes in the program, which can cause circular references that otherwise would not exist when generating ES2015 code. A workaround is to "hide" the type from the transformer: import { MyService } from './my.service';
export type Hidden<T> = T;
export class MyThing {
seven: number = 7;
constructor(private myService: Hidden<MyService>) { }
} This works because the transformer uses |
So upon talking to Alex, I think the code in question is Just needs to check for decorators, similar to @clydin / @mgechev - is this something you could help with? <3 |
The analysis is correct. There’s already a PR fix available. I just wanted to confirm that the class in question didn’t have any decorators before marking the PR as a fix for this issue. Also of note is that this only affects JIT mode. The transform as a whole is not needed for AOT which is why production doesn’t exhibit the original issue. Something else to consider (and a reason others probably haven’t encountered this) is that the application technically has circular dependencies. They are just design time rather than runtime. |
@clydin Yes, confirmed that the class didn't have a decorator. Thanks :) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 Bug report
Command (mark with an
x
)Is this a regression?
Yes, the previous version in which this bug was not present was:7.3.9
Description
I'm getting a lot of circular dependency warnings, and the app is not running after doing a dev build using
ng build
.When doing a prod build using
ng build --prod
the build compiles and runs fine.Also doing both types of builds worked perfectly in Angular 7, this problem has only started since I upgraded to Angular 8 yesterday.
🔥 Exception or Error
(above for example - there are about 50)
🌍 Your Environment
Anything else relevant?
I'm not sure why this problem has sprung up after an upgrade? It was working perfectly in Angular 7, and i haven't changed anything, other than running the upgrade to Angular 8.
I'm a bit stuck, as it's not easy to fix these problems, and there are about 50 of them - and as they weren't a problem before, I'm not sure why they would be now? Seems like a pretty massive regression?
The text was updated successfully, but these errors were encountered: