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

Closed
5 tasks done
patricklafrance opened this issue Apr 23, 2024 · 12 comments
Closed
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 :(

@danieloprado
Copy link

danieloprado commented Jun 18, 2024

After version 0.0.17 is not possible to use remoteEntry.js neither, even no one importing it 🥲

Captura de ecrã 2024-06-18, às 15 19 31

@lestersconyers
Copy link

Same issue. Following.

@danieloprado
Copy link

After version 0.0.17 is not possible to use remoteEntry.js neither, even no one importing it 🥲

Captura de ecrã 2024-06-18, às 15 19 31

Maybe is related with #2672

Copy link
Contributor

Stale issue message

@patricklafrance
Copy link
Author

@ScriptedAlchemy should this issue really be closed?

@todorgrigorov
Copy link

todorgrigorov commented Oct 10, 2024

Hey, this is still a blocking issue for us. Any updates?

@petrosD93
Copy link

Any update on this and how we can handle such issue?

@harshalhirve
Copy link

harshalhirve commented Nov 26, 2024

I am facing issue:
Failed to get manifest. #RUNTIME-003 while using MODERN.JS SSR MICRO-FRONTENDS.
@ScriptedAlchemy : Request if you can please guide on this ?
I am trying to refer to: https://github.com/module-federation/core/tree/main/apps/modernjs-ssr

image

@GiorgiSalukvadze
Copy link

@harshalhirve any updates? i have same issue

@ph1p
Copy link

ph1p commented Dec 10, 2024

In case anyone stumbles across this thread. Just check CORS. With Webpack Dev Server you only need to add headers.

Example:

devServer: {
  headers: {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
    "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
  }
}

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

No branches or pull requests