core
core copied to clipboard
[native-federation-typescript]: Configurations cannot consume an object for the host entry
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
- [x] Read the docs.
- [x] Read the common issues list.
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] Make sure this is a Module federation issue and not a framework-specific issue.
- [x] The provided reproduction is a minimal reproducible example of the bug.