diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..e6e144b702a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Fix "Could not find the next executable" on Next.js deployments (#6372) diff --git a/src/frameworks/utils.ts b/src/frameworks/utils.ts index c0d3bf04703..0aafbc845fa 100644 --- a/src/frameworks/utils.ts +++ b/src/frameworks/utils.ts @@ -24,7 +24,8 @@ import { BUILD_TARGET_PURPOSE, RequestHandler } from "./interfaces"; // the import statement into a require const { dynamicImport } = require(true && "../dynamicImport"); -const NPM_ROOT_TIMEOUT_MILLIES = 2_000; +const NPM_ROOT_TIMEOUT_MILLIES = 5_000; +const NPM_ROOT_MEMO = new Map(); /** * Whether the given string starts with http:// or https:// @@ -222,9 +223,19 @@ function scanDependencyTree(searchingFor: string, dependencies = {}): any { } export function getNpmRoot(cwd: string) { - return spawnSync("npm", ["root"], { cwd, timeout: NPM_ROOT_TIMEOUT_MILLIES }) + let npmRoot = NPM_ROOT_MEMO.get(cwd); + if (npmRoot) return npmRoot; + + npmRoot = spawnSync("npm", ["root"], { + cwd, + timeout: NPM_ROOT_TIMEOUT_MILLIES, + }) .stdout?.toString() .trim(); + + NPM_ROOT_MEMO.set(cwd, npmRoot); + + return npmRoot; } export function getNodeModuleBin(name: string, cwd: string) {