Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 tasks done
patricklafrance opened this issue Apr 23, 2024 · 2 comments
Open
5 tasks done
Assignees

Comments

@patricklafrance
Copy link

patricklafrance commented Apr 23, 2024

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

@ScriptedAlchemy
Copy link
Member

@2heal1 have idea here or is there hook for failed manifest load?

@antondrozd
Copy link

Facing the same issue. Can't use manifests because of this :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants