@@ -299,7 +299,13 @@ export const copyNextDependencies = async (ctx: PluginContext): Promise<void> =>
299
299
}
300
300
const src = join ( ctx . standaloneDir , entry )
301
301
const dest = join ( ctx . serverHandlerDir , entry )
302
- await cp ( src , dest , { recursive : true , verbatimSymlinks : true , force : true } )
302
+ const filter = ctx . constants . IS_LOCAL ? undefined : nodeModulesFilter
303
+ await cp ( src , dest , {
304
+ recursive : true ,
305
+ verbatimSymlinks : true ,
306
+ force : true ,
307
+ filter,
308
+ } )
303
309
304
310
if ( entry === 'node_modules' ) {
305
311
await recreateNodeModuleSymlinks ( ctx . resolveFromSiteDir ( 'node_modules' ) , dest )
@@ -438,3 +444,24 @@ export const verifyHandlerDirStructure = async (ctx: PluginContext) => {
438
444
)
439
445
}
440
446
}
447
+
448
+ // This is a workaround for Next.js installations in a pnpm+glibc context
449
+ // Patch required due to an intermittent upstream issue in the npm/pnpm ecosystem
450
+ // https://github.com/pnpm/pnpm/issues/9654
451
+ // https://github.com/pnpm/pnpm/issues/5928
452
+ // https://github.com/pnpm/pnpm/issues/7362 (persisting even though ticket is closed)
453
+ const nodeModulesFilter = async ( sourcePath : string ) => {
454
+ // Filtering rule for the following packages:
455
+ // - @rspack+binding-linux-x64-musl
456
+ // - @swc+core-linux-x64-musl
457
+ // - @img+sharp-linuxmusl-x64
458
+ // - @img+sharp-libvips-linuxmusl-x64
459
+ if (
460
+ sourcePath . includes ( '.pnpm' ) &&
461
+ ( sourcePath . includes ( 'linuxmusl-x64' ) || sourcePath . includes ( 'linux-x64-musl' ) )
462
+ ) {
463
+ return false
464
+ }
465
+
466
+ return true
467
+ }
0 commit comments