diff --git a/packages/angular_devkit/build_angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.ts b/packages/angular_devkit/build_angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.ts index 6ab02473781a..cd4b2aabea19 100644 --- a/packages/angular_devkit/build_angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.ts +++ b/packages/angular_devkit/build_angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.ts @@ -69,7 +69,10 @@ export function resolve( } export async function load(url: string, context: { format?: string | null }, nextLoad: Function) { - if (isFileProtocol(url)) { + const { format } = context; + + // CommonJs modules require no transformations and are not in memory. + if (format !== 'commonjs' && isFileProtocol(url)) { const filePath = fileURLToPath(url); // Remove '/' or drive letter for Windows that was added in the above 'resolve'. let source = outputFiles[relative('/', filePath)] ?? TRANSFORMED_FILES[filePath]; @@ -81,8 +84,6 @@ export async function load(url: string, context: { format?: string | null }, nex } if (source !== undefined) { - const { format } = context; - return { format, shortCircuit: true,