core icon indicating copy to clipboard operation
core copied to clipboard

[native-federation-typescript]: Configurations cannot consume an object for the host entry

Open gg-wis opened this issue 8 months ago • 1 comments

Describe the bug

I am attempting to consume types from a remote Next.js application, that has this plugin configured correctly for WebPack and is server @mf-types.zip. The consumer is a Vite based React app, which also has this plugin set up. However, my federation plugin remote configuration has an object defined instead of a string for the entry in order to change the type etc.

When running the Vite dev server, you'll get the following error in this case:

TypeError: t.split is not a function
    at k

This is because of lines 9-12 in ./src/configurations/hostPlugin.ts:

const retrieveRemoteStringUrl = (remote: string) => {
  const splittedRemote = remote.split('@');
  return splittedRemote[splittedRemote.length - 1];
};

I recommend the following fix:

const retrieveRemoteStringUrl = (remote: string | Record<string, string>) => {
	if (typeof remote === 'string') {
		const splittedRemote = remote.split('@');

		return splittedRemote[remote.length - 1]
	} 

	if (typeof remote === 'object' && "entry" in remote) { 
		const splittedRemote = remote.entry.split('@');

		return splittedRemote[splittedRemote.length - 1];
	}

	throw new Error(`Invalid type of remote: ${typeof remote}`);
  };

Reproduction

https://codesandbox.io/p/sandbox/runtime-sea-56pdkd

Used Package Manager

pnpm

System Info

System:
    OS: macOS 15.3.1
    CPU: (12) arm64 Apple M2 Pro
    Memory: 77.91 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.2 - ~/.nvm/versions/node/v20.18.2/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.18.2/bin/npm
    pnpm: 10.2.0 - ~/.nvm/versions/node/v20.18.2/bin/pnpm
  Browsers:
    Chrome: 133.0.6943.54
    Safari: 18.3

Validations

gg-wis avatar Feb 12 '25 17:02 gg-wis