core icon indicating copy to clipboard operation
core copied to clipboard

NextJS Plugin not working with Webpack v5.22.0 and up

Open timetraveler328 opened this issue 5 years ago • 3 comments

I'm not sure if it's best to file this here, in the example repo, or in the webpack repo, let me know if there's a better place for this.

I've been unable to get module federation working with the latest version of NextJS, which is using wepback 5.24.4. The explanation below uses the nextjs example at https://github.com/module-federation/module-federation-examples/tree/master/nextjs.

When running the example in the nextjs folder, I get ReferenceError: next1 is not defined. It seems that next1 is not set as a global variable in the browser.

Screen Shot 2021-03-15 at 4 06 14 PM

Though the package.json has resolutions to set the Webpack version to 5.18.0, when the webpack5 flag in nextjs is set, it ignores the resolution version and instead pulls in version 5.24.4 (you can see this by adding console.log(options.webpack.version) to the webpack function in next.config.js.

I did some testing with different version of Webpack 5 (using resolutions and an older version of nextjs before they added the webpack5 flag, you can test this in the example repo by removing the caret in front of the dependency next: "^10.0.0"), and determined that the last working version without this error was 5.21.2. Looking at the remoteEntry files that are emitted using v5.21.2 vs v5.22.0, I see that the global variable assignment is missing from the generated remoteEntry file after v5.22.0.

Working - Webpack v5.21.2: Screen Shot 2021-03-15 at 5 14 05 PM

Not working - Webpack v5.22.0 Screen Shot 2021-03-15 at 5 15 12 PM

That's as far as I've been able to trace things, I looked through Webpack's 5.22.0 release but didn't see anything obvious. I've also not been able to find a way to actually override the version of webpack 5 in the most recent version of nextjs. I'd really like to adopt module federation in our nextjs apps. Let me know if there's any more info you need. Thanks!

timetraveler328 avatar Mar 15 '21 21:03 timetraveler328

I've a very similar error with that repo :( image

bravoy93 avatar Mar 22 '21 04:03 bravoy93

I ran into the same issue. For me, the MergeRuntime command kept failing. All it does is combine these 2 together, which you need both in order to fetch the remote host. If you only load in the remoteEntry script then you'll get the above error every time.

<script src={`${process.env.APP_A_URL}/_next/static/chunks/webpack.js`}></script>
<script src={`${process.env.APP_A_URL}/_next/static/runtime/remoteEntry.js`}></script>

jcmcneal avatar Apr 15 '21 20:04 jcmcneal

have updated merge runtime

ScriptedAlchemy avatar May 22 '21 01:05 ScriptedAlchemy