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

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

Open
5 tasks done
gg-wis opened this issue Feb 12, 2025 · 1 comment
Open
5 tasks done

Comments

@gg-wis
Copy link

gg-wis commented Feb 12, 2025

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
Copy link
Author

gg-wis commented Feb 12, 2025

Will probably submit a PR tomorrow (13/02 GMT) with this fix, ran out of time today.

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

1 participant