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

loadRemote from react host (webpack) doesn't work with next.js mf #2530

Open
5 tasks done
crutch12 opened this issue May 22, 2024 · 3 comments
Open
5 tasks done

loadRemote from react host (webpack) doesn't work with next.js mf #2530

crutch12 opened this issue May 22, 2024 · 3 comments
Assignees
Labels
nextjs-mf nextjs-mf package identifier

Comments

@crutch12
Copy link
Contributor

Describe the bug

next.js mf requires next/** packages in host's shared

So it fails

// react (webpack) host
import React from 'react';
import { init, loadRemote } from '@module-federation/runtime';

init({
    name: 'host',
    remotes: [
        {
            name: 'remote',
            entry: 'http://localhost:8081/_next/static/chunks/remoteEntry.js'
        }
    ],
    force: true
})

const NextjsRemoteComponent = React.lazy(() => loadRemote('remote/nextjs-remote-component'))
const NextjsRemotePage = React.lazy(() => loadRemote('remote/nextjs-remote-page'))

function App() {
  return (
    <>
      <div>This is the React container App hosted at localhost:8080</div>
        <React.Suspense fallback="loading NextjsRemoteComponent">
            <NextjsRemoteComponent />
        </React.Suspense>
        <React.Suspense fallback="loading NextjsRemotePage">
            <NextjsRemotePage />
        </React.Suspense>
    </>
  );
}

export default App;

Error:

TypeError: Cannot read properties of undefined (reading '0')
at args.resolver (runtimePlugin.js:162:49)
at getRegisteredShare (share.esm.js:886:34)
at SharedHandler.loadShare (index.esm.js:1203:82)
at async Promise.all (:8080/index 1)
at async Module.get (index.cjs.js:285:1)
at async RemoteHandler.loadRemote (index.cjs.js:1503:1)

Error source:

host.options.shared[pkgName][0]; // replace local share scope manually with desired module

Reproduction

https://github.com/crutch12/react-host-next-remote/tree/master/react-nextjs/react-host-nextjs-remote

Used Package Manager

npm

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz
    Memory: 3.94 GB / 31.79 GB
  Binaries:
    Node: 16.16.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.15.7 - ~\AppData\Roaming\npm\pnpm.CMD
    bun: 1.1.4 - ~\AppData\Roaming\npm\bun.CMD
  Browsers:
    Edge: Chromium (123.0.2420.97)
    Internet Explorer: 11.0.22621.3527

Validations

@crutch12
Copy link
Contributor Author

@zhoushaw zhoushaw added the nextjs-mf nextjs-mf package identifier label May 28, 2024
@ScriptedAlchemy
Copy link
Member

Okay. So I think we can just do a conditional check for if next exists in host before letting the resolver take over.

@ScriptedAlchemy
Copy link
Member

#2604 This should resolve it once merge and released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nextjs-mf nextjs-mf package identifier
Projects
None yet
Development

No branches or pull requests

3 participants