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

Vite Module Federation CORS error #581

Open
farhanmalhi-dbank opened this issue Mar 5, 2024 · 4 comments
Open

Vite Module Federation CORS error #581

farhanmalhi-dbank opened this issue Mar 5, 2024 · 4 comments

Comments

@farhanmalhi-dbank
Copy link

farhanmalhi-dbank commented Mar 5, 2024

this is my host-app configuration

federation({
name: 'host-app',
filename: 'remoteEntry.js',
remotes: {
remote: 'http://localhost:3002/assets/remoteEntry.js'
},
shared: ['react', 'react-dom', '@lin/tools-component-library']
})
and this is my remote app configuration

plugins: [
...,
federation({
name: 'remote',
filename: 'remoteEntry.js',
exposes: {
'./Dashboard': './src/pages/dashboard/dashboard'
},
shared: ['react', 'react-dom', '@lib/tools-component-library']
})
],
base: 'http://localhost:3002',
server: {
open: true,
port: 3002,
cors: true
},

i can also see the file in browser at http://localhost:3002/assets/remoteEntry.js.

in my remote app terminal i can see the request but in browser it throws error

  1. Access to script at 'http://localhost:3002/assets/remoteEntry.js' from origin 'http://localhost:3001/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
  2. GET http://localhost:3002/assets/remoteEntry.js net::ERR_FAILED 200 (OK)
  3. Uncaught TypeError: Failed to fetch dynamically imported module: http://localhost:3002/assets/remoteEntry.js

Versions

  • vite-plugin-federation: v1.3.5
  • vite: v5.1.0

Reproduction

Additional Details

Steps to reproduce

What is Expected?

it should show to remote exported content in the host app

What is actually happening?

Stuck on loading, showing console error

  1. Access to script at 'http://localhost:3002/assets/remoteEntry.js' from origin 'http://localhost:3001/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
  2. GET http://localhost:3002/assets/remoteEntry.js net::ERR_FAILED 200 (OK)
  3. Uncaught TypeError: Failed to fetch dynamically imported module: http://localhost:3002/assets/remoteEntry.js
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Title: Vite Module Federation CORS error

@Tushar-Tilwani
Copy link

Facing the same issue!

@mhdriyadh367
Copy link

is it solved ?

@willy-infinid
Copy link

I'm facing a similar issue, but in my case, the problem occurred when I tried to access the remoteEntry.js file from the deployed domain for example: https://example.com/assets/remoteEntry.js. localhost to localhost is just working fine in my case.

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

5 participants