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

directive does not work when Build for production #7

Closed
hmendezm opened this issue Jun 22, 2022 · 8 comments · Fixed by #9
Closed

directive does not work when Build for production #7

hmendezm opened this issue Jun 22, 2022 · 8 comments · Fixed by #9
Assignees
Labels
bug Something isn't working

Comments

@hmendezm
Copy link

HI dkhrunov,

Sorry for bothering you. Now I am working on deploying the app in production mode. In this case, I have all remotes working standard alone. The problem is when I use the directive I got the error below. My guess is that when the directive tries to upload the component, this is not found. Note: The app works if I run serve (development mode)

do you have any idea what is the problem?
I have the following in place:

HTML

 <ng-container *mfeOutlet="'sharedcomponents/Loader';inputs: { isLoading: isLoading, messages:loadingMsg};">
  </ng-container>

Configuration

	MfeModule.forRoot({
			mfeConfig:{
 'sharedcomponents': 'http://localhost:5005/remoteEntry.js',
},
      preload: ['sharedcomponents'],
			loaderDelay: 0,
		}),

Sharedcompoenent MFE

webpack.config

  exposes: {
        'Loader':'apps/sharedcomponents/src/app/loader/loader.module.ts',
         },

Loader.module

import { LoaderComponent } from './loader.component';
import {  NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

@NgModule({
  imports: [CommonModule],
  declarations: [LoaderComponent],
  exports: [LoaderComponent]
})
export class LoaderModule {
  constructor(){
    console.log("%cLoaderModule constructor: LIBS/COMPONENTS/LOADER","color: blue; font-size: 20px");
  }
}

ERROR

329.cf6448c1ab7708fd.js:1 Error: LoaderComponent don't registered in module i
    at 329.cf6448c1ab7708fd.js:1:65453
    at Generator.next (<anonymous>)
@dkhrunov
Copy link
Owner

dkhrunov commented Jun 22, 2022

Hi, i think problem in the Configuration, when you deploy you microfront MfeModule try to find it in http://localhost:5005/remoteEntry.js

Try to provide correct host path where you deploy your MFE.

Check this article, this should help you.

@hmendezm
Copy link
Author

hmendezm commented Jun 22, 2022

Hi dkrunov and thanks for your reply
The path is correct. This is working if I use development mode. The only thing I do is to change is below. I guess has to be with the way you find the component in the module. you are using the name but when the code is optimized, the names are
replaced by letters to compress size. Do you have a working example where you build with optimizer enable?

Note: yes, I am using the approach in the article. So in this case is still local but built as production. So the path is the same. The difference is code is optimized by webpack.
project.json

"buildOptimizer": true,
"optimization": true,

ngx-mfe code

public _findComponentType<TModule = unknown, TComponent = unknown>(
		componentName: string,
		compiledModule: ModuleWithComponentFactories<TModule>
	): Type<TComponent> | undefined {
[		return [compiledModule.componentFactories.find((f)](url) => f.componentType.name === componentName)](url)
			?.componentType;
	}
}

@dkhrunov
Copy link
Owner

Hi @hmendesm!
Thanks for your bug report, I have found the source of this problem, I will update the library soon and post a new version where I will make corrections.
When I do this, I will contact you.

@dkhrunov dkhrunov added the bug Something isn't working label Jun 23, 2022
@dkhrunov dkhrunov self-assigned this Jun 23, 2022
@hmendezm
Copy link
Author

hmendezm commented Jun 23, 2022 via email

@dkhrunov
Copy link
Owner

Cool, I want to see it in action, can you create a Pull Request with your changes?

@dkhrunov
Copy link
Owner

In meantime, I`m has anouther solution, but for this you will have to exposes the component class itself, as it was before version 1.1.0, like you do it with modules.

You can check how it work before v1.1.0 source code here

This was referenced Jul 6, 2022
@dkhrunov
Copy link
Owner

dkhrunov commented Jul 7, 2022

Hello!
I introduce a new version 2.0.0, where I fixed this issue.

But with v2 I made few breaking changes, check updated documentation here and check out a Migration guide to v2

@hmendezm
Copy link
Author

hmendezm commented Jul 7, 2022 via email

@dkhrunov dkhrunov mentioned this issue Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants