Skip to content

Vite Module Federation CORS error  #581

@fmhurizen

Description

@fmhurizen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions