From 409668107d3adb29c55860527855a2fb4834a770 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 14 Jun 2023 16:55:38 -0700 Subject: [PATCH] Revert "Prefer module fields for RSC server layer" (#51316) Closes: https://github.com/vercel/next.js/issues/51309 Reverts vercel/next.js#51179 --- packages/next/src/build/webpack-config.ts | 4 --- .../app-dir/app-external/app-external.test.ts | 33 ++++++++++--------- .../react-server/3rd-party-package/page.js | 3 -- .../server-module-field/index.cjs | 1 - .../server-module-field/index.esm.js | 1 - .../server-module-field/package.json | 4 --- 6 files changed, 17 insertions(+), 29 deletions(-) delete mode 100644 test/e2e/app-dir/app-external/node_modules_bak/server-module-field/index.cjs delete mode 100644 test/e2e/app-dir/app-external/node_modules_bak/server-module-field/index.esm.js delete mode 100644 test/e2e/app-dir/app-external/node_modules_bak/server-module-field/package.json diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index 4a93193dd5650..dd7c52955acca 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -1941,10 +1941,6 @@ export default async function getBaseWebpackConfig( ], }, resolve: { - mainFields: isEdgeServer - ? mainFieldsPerCompiler[COMPILER_NAMES.edgeServer] - : // Prefer module fields over main fields for isomorphic packages on server layer - ['module', 'main'], conditionNames: reactServerCondition, alias: { // If missing the alias override here, the default alias will be used which aliases diff --git a/test/e2e/app-dir/app-external/app-external.test.ts b/test/e2e/app-dir/app-external/app-external.test.ts index ea2a4f5d39263..f76b8a9b43221 100644 --- a/test/e2e/app-dir/app-external/app-external.test.ts +++ b/test/e2e/app-dir/app-external/app-external.test.ts @@ -88,23 +88,24 @@ createNextDescribe( }) it('should resolve 3rd party package exports based on the react-server condition', async () => { - const $ = await next.render$('/react-server/3rd-party-package') - - const result = $('body').text() - - // Package should be resolved based on the react-server condition, - // as well as package's internal & external dependencies. - expect(result).toContain( - 'Server: index.react-server:react.subset:dep.server' - ) - expect(result).toContain('Client: index.default:react.full:dep.default') - - // Subpath exports should be resolved based on the condition too. - expect(result).toContain('Server subpath: subpath.react-server') - expect(result).toContain('Client subpath: subpath.default') + await next + .fetch('/react-server/3rd-party-package') + .then(async (response) => { + const result = await resolveStreamResponse(response) + + // Package should be resolved based on the react-server condition, + // as well as package's internal & external dependencies. + expect(result).toContain( + 'Server: index.react-server:react.subset:dep.server' + ) + expect(result).toContain( + 'Client: index.default:react.full:dep.default' + ) - // Prefer `module` field for isomorphic packages. - expect($('#main-field').text()).toContain('server-module-field:module') + // Subpath exports should be resolved based on the condition too. + expect(result).toContain('Server subpath: subpath.react-server') + expect(result).toContain('Client subpath: subpath.default') + }) }) it('should correctly collect global css imports and mark them as side effects', async () => { diff --git a/test/e2e/app-dir/app-external/app/react-server/3rd-party-package/page.js b/test/e2e/app-dir/app-external/app/react-server/3rd-party-package/page.js index 92e9f01672faa..33141e12f7685 100644 --- a/test/e2e/app-dir/app-external/app/react-server/3rd-party-package/page.js +++ b/test/e2e/app-dir/app-external/app/react-server/3rd-party-package/page.js @@ -1,6 +1,5 @@ import v from 'conditional-exports' import v1 from 'conditional-exports/subpath' -import { name as serverFieldName } from 'server-module-field' import Client from './client' @@ -12,8 +11,6 @@ export default function Page() { {`Server subpath: ${v1}`}
-
-
{`Server module field: ${serverFieldName}`}
) } diff --git a/test/e2e/app-dir/app-external/node_modules_bak/server-module-field/index.cjs b/test/e2e/app-dir/app-external/node_modules_bak/server-module-field/index.cjs deleted file mode 100644 index bead07e159aa3..0000000000000 --- a/test/e2e/app-dir/app-external/node_modules_bak/server-module-field/index.cjs +++ /dev/null @@ -1 +0,0 @@ -exports.name = 'server-module-field:main' diff --git a/test/e2e/app-dir/app-external/node_modules_bak/server-module-field/index.esm.js b/test/e2e/app-dir/app-external/node_modules_bak/server-module-field/index.esm.js deleted file mode 100644 index 02218634f7d07..0000000000000 --- a/test/e2e/app-dir/app-external/node_modules_bak/server-module-field/index.esm.js +++ /dev/null @@ -1 +0,0 @@ -export const name = 'server-module-field:module' diff --git a/test/e2e/app-dir/app-external/node_modules_bak/server-module-field/package.json b/test/e2e/app-dir/app-external/node_modules_bak/server-module-field/package.json deleted file mode 100644 index d6cb0ed97cb3d..0000000000000 --- a/test/e2e/app-dir/app-external/node_modules_bak/server-module-field/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "./index.cjs", - "module": "./index.esm.js" -}