diff --git a/packages/next/src/build/swc/jest-transformer.ts b/packages/next/src/build/swc/jest-transformer.ts index 3ab9cf8d9d8fd6..bc753093e44c42 100644 --- a/packages/next/src/build/swc/jest-transformer.ts +++ b/packages/next/src/build/swc/jest-transformer.ts @@ -84,6 +84,9 @@ const createTransformer: TransformerCreator< const jestConfig = getJestConfig(jestOptions) const swcTransformOpts = getJestSWCOptions({ + isServer: + jestConfig.testEnvironment === 'node' || + jestConfig.testEnvironment.includes('jest-environment-node'), filename, jsConfig: inputOptions?.jsConfig, resolvedBaseUrl: inputOptions?.resolvedBaseUrl, diff --git a/packages/next/src/build/swc/options.ts b/packages/next/src/build/swc/options.ts index 7cda8ec6142365..8a944c55db0a16 100644 --- a/packages/next/src/build/swc/options.ts +++ b/packages/next/src/build/swc/options.ts @@ -237,6 +237,7 @@ function getEmotionOptions( } export function getJestSWCOptions({ + isServer, filename, esm, modularizeImports, @@ -247,6 +248,7 @@ export function getJestSWCOptions({ pagesDir, hasServerComponents, }: { + isServer: boolean filename: string esm: boolean modularizeImports?: NextConfig['modularizeImports'] @@ -269,6 +271,7 @@ export function getJestSWCOptions({ jsConfig, hasServerComponents, resolvedBaseUrl, + isServerLayer: isServer, }) const isNextDist = nextDistPath.test(filename)