vite icon indicating copy to clipboard operation
vite copied to clipboard

v1.0.0: Error with Nuxt as host app

Open David-Sellen opened this issue 1 year ago • 20 comments

Hi there!

I have a Nuxt application acting as host and to load remote client side Vue apps. Currently we're using @originjs/vite-plugin-federation which works OK but we would like to migrate to this library instead for other reasons.

I'm trying out @module-federation/[email protected] and it works well when i test it on my simple Vue SPA host but not when I'm trying to replace the OriginJS plugin in our Nuxt host application.

I get the following error in the browser and when I check the network traffic it does not load the RemoteEntyr.js.

Uncaught (in promise) Error: [ Federation Runtime ]: Please call init first
    at error2 (share.cjs.js:26:11)
    at Object.assert2 [as assert] (share.cjs.js:18:9)
    at loadRemote (index.cjs.js:2137:11)
    at myremote_app.js:3:32

The Vite settings in the Nuxt.config

...
vite: {
    plugins: [
      federation({
        name: "ssr-host",
        remotes: {
          myremote: {
            name: "myremote",
            shareScope: "myremote",
            entry: "/assets/remoteEntry.js",
            entryGlobalName: "myremote",
            type: "module",
          },
        },
        filename: "remoteEntry.js",
        runtimePlugins: ["./mfPlugin"], // From your example. only contains console.logs.
      })
    ],
    build: {
      target: "chrome89",
      rollupOptions: {
        output: {
          manualChunks(id) {
            if (id.indexOf("/@module-federation/runtime") > -1) {
              return "mfruntime";
            }
          },
        },
      },
    },

Might there be something in this library that does not support this approach or do you guys have something that I can try out to make it work?

David-Sellen avatar Sep 02 '24 09:09 David-Sellen

The entry insertion code may not take into account the SSR application. I will fix it later.

zhangHongEn avatar Sep 02 '24 09:09 zhangHongEn

@David-Sellen thanks for your feedback. Can I ask you to add a Nuxt example please? You can add it next to the other ones. Appreciate

gioboa avatar Sep 02 '24 11:09 gioboa

SSR requires me to complete manifest.json in advance, which is originally on the roadmap, This will take some time, I will finish it this week

 WARN  [ Federation Runtime ]: [ Federation Runtime ]: Failed to get manifestJson for @namespace/viteViteRemote. The manifest URL is http://localhost:5176/.vite/manifest.json. Please ensure that the manifestUrl is accessible.
          
 Error message:
          
 Error: [ Federation Runtime ]: http://localhost:5176/.vite/manifest.json is not a federation manifest

  
  Error message:
  
  Error: [ Federation Runtime ]: http://localhost:5176/.vite/manifest.json is not a federation manifest

zhangHongEn avatar Sep 02 '24 14:09 zhangHongEn

The demo can be created, I will fix it this week

zhangHongEn avatar Sep 02 '24 15:09 zhangHongEn

That sounds great @zhangHongEn ! I created a small Nuxt example here: https://github.com/David-Sellen/vite/tree/73-error-with-nuxt-as-host-app @gioboa

David-Sellen avatar Sep 03 '24 06:09 David-Sellen

Thanks @David-Sellen 👏

gioboa avatar Sep 03 '24 13:09 gioboa

image

I used the code of nuxt remote client in nuxt host server, and got this result as expected. Next, I need to find time to check how rust and webpack handle ssr.

This problem is more complicated and should take more time.

zhangHongEn avatar Sep 08 '24 17:09 zhangHongEn

Closed by #86

gioboa avatar Sep 15 '24 11:09 gioboa

Sorry, nuxt is not yet completed. This issue needs to be reopened

---- Replied Message ---- | From | Giorgio @.> | | Date | 09/15/2024 19:47 | | To | module-federation/vite @.> | | Cc | zhn @.>, Mention @.> | | Subject | Re: [module-federation/vite] v1.0.0: Error with Nuxt as host app (Issue #73) |

Closed by #86

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

zhangHongEn avatar Sep 15 '24 12:09 zhangHongEn

Also tried to get this working, but still not working. @zhangHongEn there is an asyncentry setting in nuxt you might find useful

https://nuxt.com/docs/guide/going-further/experimental-features#asyncentry

husayt avatar Sep 26 '24 01:09 husayt

Also tried to get this working, but still not working. @zhangHongEn there is an asyncentry setting in nuxt you might find useful

https://nuxt.com/docs/guide/going-further/experimental-features#asyncentry

nuxt should wait for rolldown support

zhangHongEn avatar Sep 26 '24 03:09 zhangHongEn

Hey @David-Sellen , thanks for opening this issue, and for the examples. I'm closing this issue for now because we need to wait for rolldown support. Thanks.

gioboa avatar Sep 26 '24 15:09 gioboa

@gioboa @zhangHongEn why do we need rolldown for this? let's keep the issue open, as nuxt support will pave the way for many others like Analog, solidstart as they also use nitro.

husayt avatar Sep 26 '24 15:09 husayt

yesterday, I spent 5 hours trying to get that working and would love to see that happen, just for the sake of those hours 😅

husayt avatar Sep 26 '24 15:09 husayt

Hi! Why we have different errors?:D

I appreciate if Nuxt support will be available in the closest time. But I'm trying to use simple Vite app inside Nuxt.

image

danya-rnd avatar Oct 02 '24 22:10 danya-rnd

I tried to test Nuxt MFE with Vite remote and I added a console.log for the loading remote. It's not waiting for the promise. image

gioboa avatar Oct 04 '24 16:10 gioboa

So do you have any ideas how to fix it at this moment? As I can see this issue is marked as "Blocked by another PR" but all PRs inside this thread are already merged.

Nuxt support is really must have:)

danya-rnd avatar Oct 11 '24 00:10 danya-rnd

There are still some unresolved issues: https://github.com/nuxt/nuxt/issues/28911. The most important thing is that I really don’t have time recently. I will continue working on it when I have some free time, but it won’t be very soon.

zhangHongEn avatar Oct 11 '24 02:10 zhangHongEn

Rspack supports nuxt as well if you're in a bind.. vite may take some time if it's blocked by rolldown

ScriptedAlchemy avatar Nov 13 '24 07:11 ScriptedAlchemy

As there's been no activity for 30 days, this issue has been flagged as stale. If you'd like it to remain open, please add a comment within the next 7 days. Thank you.

github-actions[bot] avatar Nov 10 '25 19:11 github-actions[bot]