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

No module factory available for dependency type: ContextElementDependency #191

Open
raronen opened this issue Oct 23, 2019 · 3 comments
Open

Comments

@raronen
Copy link

raronen commented Oct 23, 2019

Yes, this issue seems to be covered here and here but those answered doesn't resolve this case. This case is different.

For one, I only have one version of webpack:
$ npm ls webpack [email protected] C:\LA\src\LogAnalyticsPortalWebRole -- @angular-devkit/[email protected]
-- [email protected]

Here is my code:
editor.module.ts (the lazy loaded module):

'use strict';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { EditorComponent } from "./editor.component";

@NgModule({
    declarations: [
        EditorComponent
    ],
    imports: [
        CommonModule,
    ],
    providers: [
    ],
    exports: [
        EditorComponent
    ]
})
export class EditorModule { }

lazy.module.ts (the module the contains the lazy load component):

'use strict';

import { NgModule } from '@angular/core';
import { ReactiveComponentLoaderModule } from '@wishtack/reactive-component-loader';
import { lazyLoadComponents } from'./lazyLoadComponents';


@NgModule({
    declarations: [
        ...lazyLoadComponents
    ],
    imports: [
        ReactiveComponentLoaderModule.withModule({
            moduleId: 'editor',
            loadChildren: '../editor/editor.module#EditorModule'
        }),
    ],
    providers: [
    ],
    exports: [
        ...lazyLoadComponents
    ]
})
export class LazyModule { }

app.module

@NgModule({
    declarations: [
        AppComponent,
    ],
    imports: [
        ...
        ReactiveComponentLoaderModule.forRoot()
        ...
    ],
    providers: [
    ],
    entryComponents: [
        ...lazyLoadComponents
    ]
})
export class AppModule { ... }

editor-initiator.component.ts (the lazy load component):

`import { Component } from '@angular/core';
import { downgradeComponent } from '@angular/upgrade/static';

@Component({
	selector: 'la-editor-initiator',
	template: `
	<h1>editor-initiator works!</h1>

	<wt-lazy
	[location]="editorComponentLocation" >
	</wt-lazy>`,
})
export class EditorInitiatorComponent {
	editorComponentLocation = {
		moduleId: 'editor',
		selector: 'wt-editor'
	};
}

angular.module('kibana').directive('laEditorInitiator', downgradeComponent({ component: EditorInitiatorComponent }) as angular.IDirectiveFactory);`

I debugged the webpack code and I noticed that in Compilation.js:696
image

the this.dependencyFactories has the ContextElementDependency module in its map but for some reason the this.dependencyFactories.get(dep.constructor) returns undefined.

I hope this can help.

@yjaaidi
Copy link
Contributor

yjaaidi commented Oct 24, 2019

Hi @raronen,
Can you try moving this import:

ReactiveComponentLoaderModule.withModule({
  moduleId: 'editor',
  loadChildren: '../editor/editor.module#EditorModule'
}),

...to your AppModule?
That's probably where the issues comes from.

Let me know how it works for you.

@raronen
Copy link
Author

raronen commented Oct 27, 2019

I ommitted the .withModule from LazyModule and put it in AppModule.
I actually tried that before, sadly, it didn't work.

Same error:
No module factory available for dependency type: ContextElementDependency

@TravBradfield
Copy link

@raronen Have you had any success with this problem? Please let us know.

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

3 participants