-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
The remote module is missing on the Window when running in the sandbox of the micro-frontend framework micro-app. #2663
Comments
use a runtime plugin instead of promise new promise.
https://module-federation.io/plugin/dev/index.html You can also set the library type if the default var is unreliable. library: { |
use the beforeRequest hook, you can look in module federation examples repo at runtime-plugin folder |
THX.
` So, how should I modify the configuration when the module federation throws such an error? |
Update the repo please so i can see |
Sorry,I have updated the code, you can see it now。 |
Stale issue message |
Describe the bug
I load sub-application app_1 in a container based on the micro-frontend framework micro-app, and app_1 uses module federation to obtain the remote module of sub-application app_2.
Both sub-applications app_1 and app_2 can run independently, and module federation is effective;
When app_2 is loaded in the container, it can also run normally;
But after loading app_1 in the container, app_1 will report an error where it uses the remote module.
from react.development.js:1409's error:
Uncaught TypeError: Cannot read properties of undefined (reading 'get')
while loading "./Page" from webpack/container/reference/app_2
This error from app_2's webpack.config.js;
I don't understand why window.app_2 doesn't exist
The following is its module federation configuration:
new ModuleFederationPlugin({ name: 'app_1', filename: 'remoteEntry.js', remotes: { // 为什么要这样写?详见: https://github.com/module-federation/module-federation-examples/issues/1142 app_2:
promise new Promise(resolve => {const remoteUrl = 'http://127.0.0.1:3002/remoteEntry.js'
const script = document.createElement('script')
script.src = remoteUrl
script.onload = () => {
console.log(window, window.rawWindow, window.app_2, 'app_2')
const proxy = {
get: (request) => window.app_2.get(request),
init: (arg) => {
try {
return window.app_2.init(arg)
} catch(e) {
console.log('remote container already initialized')
}
}
}
resolve(proxy)
}
document.head.appendChild(script);
})
}, shared: { ...deps, 'react-router-dom': { singleton: true, }, 'react-dom': { singleton: true, }, react: { singleton: true, }, }, }),
Reproduction
https://github.com/zhangxilong-43/module_federation_case/tree/master
Used Package Manager
pnpm
System Info
Validations
The text was updated successfully, but these errors were encountered: