question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NgModule entryComponents shaked out of the production bundle

See original GitHub issue

Bug 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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sumitaroracommented, May 8, 2017

@matheo @lauriliivamagi @glebsts Seems to be issue with UglifyJsPlugin webpack plugin. Removing that and running the prod build works fine. It doesn;t seems to be resolving an instance of the component properly.

1reaction
Isteriuscommented, Jun 7, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Ivy ignoring entryComponents setting - Stack Overflow
Everything works as expected when running in dev mode via ng serve . As is often the case, things doesn't go smoothly with...
Read more >
Bye-Bye entryComponents?. With angular 9, there ... - Medium
They'd be present in the produced bundle only if they are specified as entryComponents. This basically means that all the routable components will...
Read more >
Doubt about NgModule and Components - Ionic Forum
My question is: Isn't Tree Shaking supposed to trim what isn't being used and therefore the final bundle only contains the code that...
Read more >
Entry components - Angular
An entry component is any component that Angular loads imperatively, (which means you're not referencing it in the template), by type. You specify...
Read more >
the Ivy League: Lazy Loading Components in Angular v9
The neat thing is that thanks to tree-shaking, if the only place that we use ... When we create the production bundle for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found