From 85fd3d9c44ccb22ba8d8c97e0114c560dd6c7204 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 23 Feb 2023 14:41:45 +0100 Subject: [PATCH 1/4] Fix edge runtim path slashes mismatch on windows --- .../webpack/plugins/flight-client-entry-plugin.ts | 5 ++++- .../build/webpack/plugins/flight-manifest-plugin.ts | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts b/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts index c9ed083d6825c..3071f237b61a9 100644 --- a/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts @@ -594,7 +594,10 @@ export class FlightClientEntryPlugin { const clientLoader = `next-flight-client-entry-loader?${stringify({ modules: this.isEdgeServer ? clientImports.map((importPath) => - importPath.replace('next/dist/esm/', 'next/dist/') + importPath.replace( + /next[\\/]dist[\\/]esm[\\/]/, + path.join('next', 'dist') + ) ) : clientImports, server: false, diff --git a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts index d2c7dab0890c8..2af673f11ee00 100644 --- a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import path from 'path' import { webpack, sources } from 'next/dist/compiled/webpack/webpack' import { CLIENT_REFERENCE_MANIFEST, @@ -325,9 +326,13 @@ export class FlightManifestPlugin { // The client compiler will always use the CJS Next.js build, so here we // also add the mapping for the ESM build (Edge runtime) to consume. - if (/\/next\/dist\//.test(resource)) { - manifest[resource.replace(/\/next\/dist\//, '/next/dist/esm/')] = - moduleExports + if (/[\\/]next[\\/]dist[\\/]/.test(resource)) { + manifest[ + resource.replace( + /next[\\/]dist[\\/]/, + path.join('next', 'dist', 'esm') + ) + ] = moduleExports } manifest.__ssr_module_mapping__ = moduleIdMapping From b9ffd051bf433e458cd03dbba16c69a12945e912 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 23 Feb 2023 14:49:12 +0100 Subject: [PATCH 2/4] fix sep --- .../next/src/build/webpack/plugins/flight-manifest-plugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts index 2af673f11ee00..5a5261ef643f1 100644 --- a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts @@ -329,8 +329,8 @@ export class FlightManifestPlugin { if (/[\\/]next[\\/]dist[\\/]/.test(resource)) { manifest[ resource.replace( - /next[\\/]dist[\\/]/, - path.join('next', 'dist', 'esm') + /[\\/]next[\\/]dist[\\/]/, + path.sep + path.join('next', 'dist', 'esm') + path.sep ) ] = moduleExports } From 39a10645c9127864aea7f8c564d9658e373ad9d4 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 23 Feb 2023 14:50:51 +0100 Subject: [PATCH 3/4] fix trailling sep --- .../src/build/webpack/plugins/flight-client-entry-plugin.ts | 2 +- .../next/src/build/webpack/plugins/flight-manifest-plugin.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts b/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts index 3071f237b61a9..223427f8a9f7f 100644 --- a/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts @@ -596,7 +596,7 @@ export class FlightClientEntryPlugin { ? clientImports.map((importPath) => importPath.replace( /next[\\/]dist[\\/]esm[\\/]/, - path.join('next', 'dist') + 'next/dist/'.replace(/\//g, path.sep) ) ) : clientImports, diff --git a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts index 5a5261ef643f1..051312282bbe2 100644 --- a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts @@ -330,7 +330,7 @@ export class FlightManifestPlugin { manifest[ resource.replace( /[\\/]next[\\/]dist[\\/]/, - path.sep + path.join('next', 'dist', 'esm') + path.sep + '/next/dist/esm/'.replace(/\//g, path.sep) ) ] = moduleExports } From 528defac13568a48807b61af47dcec1e74ea734d Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 23 Feb 2023 14:57:45 +0100 Subject: [PATCH 4/4] check leading sep --- .../src/build/webpack/plugins/flight-client-entry-plugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts b/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts index 223427f8a9f7f..310dc5bd2883d 100644 --- a/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts @@ -595,8 +595,8 @@ export class FlightClientEntryPlugin { modules: this.isEdgeServer ? clientImports.map((importPath) => importPath.replace( - /next[\\/]dist[\\/]esm[\\/]/, - 'next/dist/'.replace(/\//g, path.sep) + /[\\/]next[\\/]dist[\\/]esm[\\/]/, + '/next/dist/'.replace(/\//g, path.sep) ) ) : clientImports,