Skip to content

Host preloading script loads assets from incorrect remote when base not explicit for cross domain remotes #242

Open
@lmiller1990

Description

I am trying to migrate from webpack to vite. It's mostly working, except one issue, when the host and remote are deployed on separate domains.

Minimal reproduction: https://github.com/lmiller1990/vite-module-federation-bug

There is a bug where, for production builds (not vite dev) the host will preload assets from its own domain. The remote IS able to load exposed assets from the host, though. Weird!

You can reproduce this by running ./reproduction.sh:

chmod +x reproduction.sh
./reproduction.sh

This will do a non minified, production build, and serve both apps using the serve static server.

Visiting the remote, http://localhost:4000, is fine. It loads a remote module exposed from the host, http://localhost:3000, which logs a greeting (see the console).

Visitng the host, http://localhost:3000, however, shows the issue. The preload-helper tries to load the remote asset, such as place.js, from http://localhost:3000/assets/place-DpMnJR6N.js - it should be from http://localhost:4000/assets/place-DpMnJR6N.js.

The problem is more clear when you look at the preload code:

const scriptRel = 'modulepreload';
const assetsURL = function(dep) { return "/" + dep };

All assets are preloaded from /.

This does NOT happen with vite dev. If the domains are the same, it works as expected:

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