originjs / vite-plugin-federation

Module Federation for vite & rollup
Other
2.39k stars 241 forks source link

Error Loading Remote Component with Vite Plugin Federation in Angular #635

Open Seifenn opened 1 month ago

Seifenn commented 1 month ago

I am attempting to test the Vite plugin federation using Angular. When loading the remote application in the host, I encounter the following error: Loading component: b: NG0203. I didn’t find examples of testing the Vite plugin federation using Angular, which is why I decided to build one, and I'm facing this issue.

Versions

Reproduction

Here is a GitHub repository where I have both the host and remote applications:
GitHub Repository

i'm loading the remote using

const module = (await import("remote_app/Button")).default;
 this.viewContainer.createComponent(module.CounterButtonComponent, {
        injector: this.injector,
      });

here is my vite config for the remote

export default defineConfig(({ mode }) => ({
  build: {
    target: ["es2020"],
  },
  resolve: {
    mainFields: ["module"],
  },
  plugins: [
    federation({
      name: "remote-app",
      filename: "remoteEntry.js",
      // Modules to expose
      exposes: {
        "./Button": "./src/components/counter/counter-button.component.ts",
      },
    }),
    angular(),
  ],
}));

And here is my vite config for the host

export default defineConfig(({ mode }) => ({
  build: {
    target: ["es2020"],
  },
  resolve: {
    mainFields: ["module"],
  },
  plugins: [
    federation({
      name: "host-app",
      remotes: {
        remote_app: "http://localhost:5175/remoteEntry.js",
      },
    }),
    angular(),
  ],
}));

Steps to reproduce

What is Expected?

I'm excpected to get the remote launching on host and displaying the counter button.

What is actually happening?

When i launch the project and try to load the remote i get the following error image Knowing that the remote entry file is present in a http-server

gioboa commented 1 month ago

Hi @Seifenn I created a PR in your repo. I solve the problem. :wink: