From aa2586217723ba7d30c95f78d780d9d6c9af0adf Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Fri, 21 Feb 2025 10:28:03 -0800 Subject: [PATCH] =?UTF-8?q?This=20uses=20`normalModule.type`=20to=20determ?= =?UTF-8?q?ine=20the=20source=20module=E2=80=99s=20type=20rather=20than=20?= =?UTF-8?q?accessing=20a=20value=20on=20`normalModule.parser`,=20which=20d?= =?UTF-8?q?oesn=E2=80=99t=20exist=20with=20rspack.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test Plan: CI --- packages/next/errors.json | 3 ++- .../loaders/next-flight-loader/index.ts | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/next/errors.json b/packages/next/errors.json index 4d883103e3db6..26420e3ee3712 100644 --- a/packages/next/errors.json +++ b/packages/next/errors.json @@ -648,5 +648,6 @@ "647": "@rspack/core is not available. Please make sure `@next/plugin-rspack` is correctly installed.", "648": "@rspack/plugin-react-refresh is not available. Please make sure `@next/plugin-rspack` is correctly installed.", "649": "Cache handlers not initialized", - "650": "experimental.nodeMiddleware" + "650": "experimental.nodeMiddleware", + "651": "Unexpected module type %s" } diff --git a/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts b/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts index e402f884c7778..f6a86b45102b5 100644 --- a/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts +++ b/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts @@ -1,4 +1,4 @@ -import type { webpack } from 'next/dist/compiled/webpack/webpack' +import type { NormalModule, webpack } from 'next/dist/compiled/webpack/webpack' import { RSC_MOD_REF_PROXY_ALIAS } from '../../../../lib/constants' import { BARREL_OPTIMIZATION_PREFIX, @@ -97,7 +97,7 @@ export default function transformSource( if (buildInfo.rsc?.type === RSC_MODULE_TYPES.client) { const assumedSourceType = getAssumedSourceType( module, - (module.parser as javascript.JavascriptParser).sourceType + sourceTypeFromModule(module) ) const clientRefs = buildInfo.rsc.clientRefs! @@ -171,3 +171,17 @@ module.exports = createProxy(${stringifiedResourceKey}) ) this.callback(null, replacedSource, sourceMap) } + +function sourceTypeFromModule(module: NormalModule): SourceType { + const moduleType = module.type + switch (moduleType) { + case 'javascript/auto': + return 'auto' + case 'javascript/dynamic': + return 'script' + case 'javascript/esm': + return 'module' + default: + throw new Error('Unexpected module type ' + moduleType) + } +}