vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

Failed to fetch dynamically imported module: http://localhost:5001/assets/remoteEntry.js

Open ycy1621260121 opened this issue 2 years ago • 20 comments

vite + [email protected] Failed to fetch dynamically imported module: http://localhost:5001/assets/remoteEntry.js

ycy1621260121 avatar Feb 22 '23 03:02 ycy1621260121

Is http://localhost:5001/assets/remoteEntry.js an accessible address? it should point to a JavaScript file

Jiannan-dev avatar Feb 22 '23 08:02 Jiannan-dev

I also have this problem, I can access this link. You can see the code. Error: Uncaught (in promise) TypeError: Failed to fetch dynamically imported module:http://localhost:3000/assets/remoteEntry.js

package.json

"dependencies": {
    "@originjs/vite-plugin-federation": "^1.2.3",
    "vite-plugin-top-level-await": "^1.3.1",
    "vue": "^3.3.4"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^4.2.3",
    "vite": "^4.4.0"
  }

Remote

export default defineConfig({
  server:{
    port: 8080
  },
  cacheDir: 'node_modules/.cacheDir',
  plugins: [
    vue(),
    federation({
      name: 'remote',
      filename: 'remoteEntry.js',
      exposes: {
        './Test': './src/components/TestVue.vue'
      },
      shared: ["vue"],
      cors: true
    }),
    topLevelAwait({
      promiseExportName: "__tla",
      promiseImportName: i => `__tla_${i}`
    })
  ],
  build: {
    assetsInlineLimit: 40960,
    minify: true,
    cssCodeSplit: false,
    sourcemap:true,
    rollupOptions: {
      output: {
        minifyInternalExports: false
      }
    }
  }
})

Host

export default defineConfig({
    server: {
      port: 4000
    },
    cacheDir: 'node_modules/.cacheDir',
    plugins: [
        vue(),
        federation({
            name: 'host',
            filename: 'remoteEntry.js',
            remotes: {
                remote: 'http://localhost:3000/assets/remoteEntry.js'
            },
            shared: ["vue"]
        }),
        topLevelAwait({
          promiseExportName: "__tla",
          promiseImportName: i => `__tla_${i}`
        })
    ],
    build: {
      target: 'esnext',
      minify: false,
      cssCodeSplit: true,
      rollupOptions: {
        output: {
          format: 'esm',
          entryFileNames: 'assets/[name].js',
          minifyInternalExports: false,
        },
      },
    }
})

Host - main.js

import { createApp, defineAsyncComponent } from 'vue'
import './style.css'
import App from './App.vue'
const RemoteTest = defineAsyncComponent(() => import("remote/Test"));
const app = createApp(App);
app.component("RemoteTest", RemoteTest)
app.mount('#app')

Host - App.vue

<template>
  <RemoteTest />
</template>

Darkdreams avatar Jul 18 '23 15:07 Darkdreams

Is http://localhost:5001/assets/remoteEntry.js an accessible address? it should point to a JavaScript file

Do u solve it?

moygospadin avatar Aug 24 '23 18:08 moygospadin

any updates on it ?

YKalashnikov avatar Nov 16 '23 22:11 YKalashnikov

@ycy1621260121 @Darkdreams @moygospadin @YKalashnikov I also get this issue. I can access http://localhost:5001/assets/remoteEntry.js when I go to that URL and I see the JS code, but the host app fails to load it for some reason. Did any of you figure out what is going on?

alexyork avatar May 07 '24 06:05 alexyork