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

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

Open
Seifenn opened this issue Sep 27, 2024 · 0 comments
Open

Comments

@Seifenn
Copy link

Seifenn commented Sep 27, 2024

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

  • vite-plugin-federation: v1.3.6
  • vite: v5.4.1

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

  • Clone the repo
  • npm i (for both host and remote)
  • npm run build (remote app)
  • npm i http-server (to launch a local server with the remote entry file)
  • npm run dev (for the host to test)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant