Skip to content

Commit

Permalink
This uses normalModule.type to determine the source module’s type r…
Browse files Browse the repository at this point in the history
…ather than accessing a value on `normalModule.parser`, which doesn’t exist with rspack.

Test Plan: CI
  • Loading branch information
wbinnssmith committed Feb 22, 2025
1 parent 445a3ff commit aa25862
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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)
}
}

0 comments on commit aa25862

Please # to comment.