From 8fe3d22c4434500ee3923f114a9597b2dad5f1ae Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Mon, 25 Nov 2024 13:36:19 -0700 Subject: [PATCH] fix(nextjs): ensure next apps config is correctly checked when using jest (#29066) ## Current Behavior When we create a new Next.js app it checks if `tsconfig.app.json` exists else it throws an error. ## Expected Behavior It should check for `tsconfig.json` instead of `tsconfig.app.json` ## Related Issue(s) Fixes #29035 (cherry picked from commit cbc19c54aefc06358a7be96cff7eba178ea3a4a6) --- .../generators/configuration/lib/update-tsconfig.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/jest/src/generators/configuration/lib/update-tsconfig.ts b/packages/jest/src/generators/configuration/lib/update-tsconfig.ts index 8d059bd3f0d1b..42ea392a5bf67 100644 --- a/packages/jest/src/generators/configuration/lib/update-tsconfig.ts +++ b/packages/jest/src/generators/configuration/lib/update-tsconfig.ts @@ -42,6 +42,16 @@ export function updateTsConfig( root, options.runtimeTsconfigFileName ); + // If the app is Next.js it will not have a tsconfig.app.json + const extensions = ['js', 'ts', 'mjs', 'cjs']; + const hasNextConfig = extensions.some((ext) => + host.exists(joinPathFragments(root, `next.config.${ext}`)) + ); + + if (hasNextConfig && projectType === 'application') { + runtimeTsconfigPath = joinPathFragments(root, 'tsconfig.json'); + } + if (!host.exists(runtimeTsconfigPath)) { // the user provided a runtimeTsconfigFileName that doesn't exist, so we throw an error throw new Error(