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

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

Open
ycy1621260121 opened this issue Feb 22, 2023 · 8 comments

Comments

@ycy1621260121
Copy link

ycy1621260121 commented Feb 22, 2023

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

@ruleeeer
Copy link
Collaborator

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

@Darkdreams
Copy link

Darkdreams commented Jul 18, 2023

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>

@moygospadin
Copy link

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

Do u solve it?

@YKalashnikov
Copy link

any updates on it ?

@alexyork
Copy link

alexyork commented May 7, 2024

@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?

@QC2168
Copy link

QC2168 commented Oct 1, 2024

How did you solve the problem

@vergil004
Copy link

Same problem. Anybody solved?

@shinderahul
Copy link

Is there any resolution on this?

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

9 participants