Skip to content

Vite module federation plugin does not work with the Vite React Router plugin #12966

@poenneby

Description

@poenneby

I'm using React Router as a...

framework

Reproduction

https://github.com/poenneby/mf-vanilla-react-router

pnpm install
pnpm dev

System Info

System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 88.98 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.1 - ~/.nvm/versions/node/v20.18.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.18.1/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v20.18.1/bin/npm
    pnpm: 9.15.4 - ~/.nvm/versions/node/v20.18.1/bin/pnpm
  Browsers:
    Chrome: 130.0.6723.59
    Safari: 17.6

Used Package Manager

pnpm

Expected Behavior

The vite module federation plugin should work with the reactRouter plugin in React Router framework mode

Minimal working example of module federation with React Vite plugin: https://github.com/poenneby/mf-vanilla-vite-react

Actual Behavior

Adding the federation plugin to the host vite config causes application to fail with require is not defined

react-router-host dev$ react-router dev
[136 lines collapsed]
│ |- ReferenceError: require is not defined
│     at eval (/mf-vanilla-react-router/react-router-host/node_modules/__mf__virtual/host__loadShare__react__loadShare__.js:8:25)
│     at instantiateModule (file:///mf-vanilla-react-router/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-CHZK…
│ 3:43:34 PM [vite] Error when evaluating SSR module virtual:react-router/server-build:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions