@@ -121,6 +121,7 @@ const buildClientRemotes = (federationPluginOptions, webpack) => {
121121 } , { } ) ;
122122 return clientRemotes ;
123123} ;
124+
124125const nextInternals = {
125126 "next/dynamic" : {
126127 requiredVersion : false ,
@@ -405,18 +406,31 @@ const withModuleFederation =
405406 ) ) ;
406407
407408 let loadableContent ;
408- try {
409+ if (
410+ fs . existsSync (
411+ path . join (
412+ compilation . options . output . path ,
413+ "../../federated-loadable-manifest.json"
414+ )
415+ )
416+ ) {
409417 loadableContent = require ( path . join (
410418 compilation . options . output . path ,
411- "../federated-loadable-manifest.json"
419+ "../../ federated-loadable-manifest.json"
412420 ) ) ;
413- } catch ( e ) {
414- log (
421+ } else if (
422+ fs . existsSync (
415423 path . join (
416424 compilation . options . output . path ,
417425 "../federated-loadable-manifest.json"
418426 )
419- ) ;
427+ )
428+ ) {
429+ loadableContent = require ( path . join (
430+ compilation . options . output . path ,
431+ "../federated-loadable-manifest.json"
432+ ) ) ;
433+ } else {
420434 log (
421435 "no federated loadable manifest found, it doesnt look like there are any local dynamic imports"
422436 ) ;
@@ -627,12 +641,25 @@ const withModuleFederation =
627641
628642 // in production or on server build use tapAsync to wait for the full compilation of the sidecar
629643 if ( isProd || compiler . options . mode === "production" ) {
630- compiler . hooks . afterCompile . tapAsync (
631- "NextFederation" ,
632- ( compilation , done ) => {
633- run ( compilation , done ) ;
644+ compiler . hooks . run . tap ( "NextFederation" , ( compilation ) => {
645+ if (
646+ compilation . name === "server" ||
647+ compilation . name === "client"
648+ ) {
649+ const sidecarCompile = new Promise ( ( res ) => {
650+ run ( compilation , ( err ) => res ( err ) ) ;
651+ } ) ;
652+
653+ compiler . hooks . afterCompile . tapAsync (
654+ "NextFederation" ,
655+ ( compilation , done ) => {
656+ sidecarCompile . then ( ( res ) => {
657+ done ( res ) ;
658+ } ) ;
659+ }
660+ ) ;
634661 }
635- ) ;
662+ } ) ;
636663 } else {
637664 compiler . hooks . afterCompile . tap (
638665 "NextFederation" ,
0 commit comments