From 618dc2ee631ccc390cdfb6871c40e9ab2c50b627 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 5 May 2023 03:40:23 -0700 Subject: [PATCH] Fix require-hook with just pages on deploy (#49274) --- packages/next/src/build/index.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index fd5f0255f109d..044b7404e2e01 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -283,8 +283,12 @@ export default async function build( const publicDir = path.join(dir, 'public') const isAppDirEnabled = !!config.experimental.appDir + const { pagesDir, appDir } = findPagesDir(dir, isAppDirEnabled) + NextBuildContext.pagesDir = pagesDir + NextBuildContext.appDir = appDir + hasAppDir = Boolean(appDir) - if (isAppDirEnabled) { + if (isAppDirEnabled && hasAppDir) { if (!process.env.__NEXT_TEST_MODE && ciEnvironment.hasNextSupport) { const requireHook = require.resolve('../server/require-hook') const contents = await promises.readFile(requireHook, 'utf8') @@ -297,11 +301,6 @@ export default async function build( } } - const { pagesDir, appDir } = findPagesDir(dir, isAppDirEnabled) - NextBuildContext.pagesDir = pagesDir - NextBuildContext.appDir = appDir - hasAppDir = Boolean(appDir) - const isSrcDir = path .relative(dir, pagesDir || appDir || '') .startsWith('src')