Skip to content

vite with SSR: require is not defined #156

Open
@omridevk

Description

@omridevk

when using SSR, I am getting the following error:

11:02:24 AM [vite] Error when evaluating SSR module /node_modules/__mf__virtual/host_mf_2_page_mf_2_app__loadRemote__remote_mf_1_remote_mf_2_app__loadRemote__.js:
|- ReferenceError: require is not defined

see stackblitz for reproduction:
https://stackblitz.com/edit/github-ad1c93-e4uuvj?file=vite.config.ts,src/main.jsx,test.js

vite config:

import { defineConfig } from 'vite';
import { federation } from '@module-federation/vite';

export default defineConfig({
  ssr: {
    optimizeDeps: {
      include: ['__mf__virtual', '@module-federation/runtime'],
    },
  },
  plugins: [
    federation({
      name: 'host-page-app',
      remotes: {
        remote: {
          type: 'module',
          name: 'remote',
          entry: 'http://test/remoteEntry.js',
          entryGlobalName: 'remote',
          shareScope: 'default',
        },
      },
      filename: 'remoteEntry.js',
    }),
  ],
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    COMMUNITY: PR is welcomedWe think it's a good feature to have but would love for the community to help with the PR for ithelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions