Skip to content

"Failed to fetch" error when trying to fetch the manifest of an offline remote. #2362

Closed as not planned
@patricklafrance

Description

@patricklafrance

Describe the bug

When trying to fetch the manifest file of a remote with the following configuration:

import ModuleFederation from "@module-federation/enhanced/webpack";

new ModuleFederation.ModuleFederationPlugin({
    name: "host",
    remotes: {
        "remote1": "remote1@http://localhost:8081/mf-manifest.json"
    }
})

If the remote is offline, a fetch error is thrown:

[ Federation Runtime ]: [ Federation Runtime ]: [ Federation Runtime ]: [ Federation Runtime ]: [ Federation Runtime ]: [ Federation Runtime ]: [ Federation Runtime ]: [ Federation Runtime ]: [ Federation Runtime ]: [ Federation Runtime ]: [ Federation Runtime ]: Failed to get manifestJson for remote1. The manifest URL is http://localhost:8081/mf-manifest.json. Please ensure that the manifestUrl is accessible.

Error message:

TypeError: Failed to fetch

Even if a errorLoadRemote hook is configured to catch the error, it still fails:

export default function () {

    const getErrorMessage = (id, error) => `remote ${id} is offline due to error: ${error}`;
  
    const getModule = (pg, from) => {
      if (from === 'build') {
        return () => ({
          __esModule: true,
          default: pg,
        });
      } else {
        return {
          default: pg,
        };
      }
    };
  
    return {
      name: 'offline-remote-plugin',
      errorLoadRemote({id, error, from}) {
        console.error(id, 'offline');
        const pg = function () {
          console.error(id, 'offline', error);
          return getErrorMessage(id, error);
        };
  
        return getModule(pg, from);
      },
    };
  }
import ModuleFederation from "@module-federation/enhanced/webpack";
import { createRequire } from "node:module";

const require = createRequire(import.meta.url);

new ModuleFederation.ModuleFederationPlugin({
    name: "host",
    remotes: {
        "remote1": "remote1@http://localhost:8081/mf-manifest.json"
    },
    runtimePlugins: [require.resolve("./offlineRemotePlugin.js")]
})

If the error is catched when using the loadRemote function, it also fails:

await loadRemote("remote1/HelloWorld.jsx")
    .then(mod => {
        console.log("Loaded remote 1", mod);
    })
    .catch(() => console.log("Failed to load remote 1"));

BUT, if I update the remote configuration to fetch a remoteEntry.js file instead of a manifest file, everything works as expected, the error is catched by either the errorLoadRemote hook or the catch handler:

import ModuleFederation from "@module-federation/enhanced/webpack";

new ModuleFederation.ModuleFederationPlugin({
    name: "host",
    remotes: {
        "remote1": "remote1@http://localhost:8081/remoteEntry.js"
    }
})

Reproduction

https://github.com/patricklafrance/mf-enhanced-manifest-bug

Used Package Manager

pnpm

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 13.30 GB / 31.70 GB
  Binaries:
    Node: 21.7.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.15.4 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Chrome: 124.0.6367.61
    Edge: Chromium (123.0.2420.97)

Validations

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions