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

Adding element to page with id that matches remote's name causes TypeError: remoteEntryExports.init is not a function #2737

Closed
5 tasks done
VityaSchel opened this issue Jul 8, 2024 · 2 comments

Comments

@VityaSchel
Copy link

Describe the bug

another 1.5 hours wasted on some questionable decisions made by authors of @module-federation/next-mf lol
The title is self explanatory:

const RemoteFiles = process.browser ? React.lazy(() => import('files/main')) : () => null
/// ...
return (
<a id='files'></a>
<RemoteFiles />
)

this causes errors TypeError: remoteEntryExports.init is not a function and files/main offline
this is because from old ancient times browsers put elements to window object by their id, so in the example above if we access window.files it will be <a> element, but it so happened that authors if this library also pollute window global space by putting some object there by remote name, so when it tries to access window.files instead of getting internal object it accesses DOM element which does not have init method
possible workarounds:

  • for contributors: fix library and do not put anything to window or at least make a special private space or use hashed remotes names
  • for users: prepend remotes names with some unique name that will never appear in window properties

Reproduction

https://github.com/module-federation/core

Used Package Manager

npm

System Info

latest @module-federation/next-mf version

Validations

@ScriptedAlchemy
Copy link
Member

ScriptedAlchemy commented Jul 9, 2024

Not our decisions. This is how it works on webpack. If I prefix or hash the name of the remote then how will you know what it called / how will it work with other parts of the ecosystem.
You can send a pr to improve the error message we throw

@ScriptedAlchemy
Copy link
Member

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

2 participants