NgModule entryComponents shaked out of the production bundle
See original GitHub issueBug Report or Feature Request (mark with an x
)
- [x] bug report
- [ ] feature request
Versions.
@angular/cli: 1.0.0
node: 7.6.0
os: linux x64
@angular/animations: 4.0.1
@angular/common: 4.0.1
@angular/compiler: 4.0.1
@angular/core: 4.0.1
@angular/forms: 4.0.1
@angular/http: 4.0.1
@angular/platform-browser: 4.0.1
@angular/platform-browser-dynamic: 4.0.1
@angular/router: 4.0.1
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.1
Ubuntu 16.04
Repro steps.
I just followed the example on Dynamic Component Loading, and it says:
If your app happens to bootstrap or dynamically load a component by type in some other manner, you must add it to entryComponents explicitly.
In order to ensure that the compiler will still generate a factory, dynamically loaded components have to be added to their NgModule’s entryComponents array.
So, building the App should work, but it doesn’t:
> Error: No component factory found for undefined. Did you add it to @NgModule.entryComponents?
The log given by the failure.
I have an initial state defined like:
const initial: WizardState = {
component: InitialStepComponent
}
but after the tree shaking it becomes something like:
const initial: WizardState = {
component: undefined
}
and throws:
ERROR Error: No component factory found for undefined. Did you add it to @NgModule.entryComponents?
at y (polyfills.563dbf3….bundle.js:36)
at J (vendor.e44d5ed….bundle.js:225)
at t.resolveComponentFactory (vendor.e44d5ed….bundle.js:365)
at t.resolveComponentFactory (vendor.e44d5ed….bundle.js:365)
at main.630b622….bundle.js:1
at t.invokeTask (polyfills.563dbf3….bundle.js:36)
at Object.onInvokeTask (vendor.e44d5ed….bundle.js:365)
at t.invokeTask (polyfills.563dbf3….bundle.js:36)
at e.runTask (polyfills.563dbf3….bundle.js:36)
at invoke (polyfills.563dbf3….bundle.js:36)
at n (polyfills.563dbf3….bundle.js:15)
Desired functionality.
Building an app with dynamic components loading ok after tree-shaking.
Mention any other details that might be useful.
Note that I’m not using string component names as in #2965. I’m using the Type and I’ve built a repo to demo that production builds doesn’t work:
https://github.com/matheo/ng-dynacomponents
Dev build: https://matheo.github.io/ng-dynacomponents/dev/ (works) Production: https://matheo.github.io/ng-dynacomponents/prod/ (broken)
Thanks in advance for any tip! cc @filipesilva
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:16 (4 by maintainers)
@matheo @lauriliivamagi @glebsts Seems to be issue with
UglifyJsPlugin
webpack plugin. Removing that and running theprod
build works fine. It doesn;t seems to be resolving an instance of the component properly.Same here, guys. I’ve just disabled Uglify Plugin and everything works just fine. I can live without it for a while, but hope you’ll be able to fix this bug.