Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix "Could not find the next executable" on Next.js deployments (#6372)
15 changes: 13 additions & 2 deletions src/frameworks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>();

/**
* Whether the given string starts with http:// or https://
Expand Down Expand Up @@ -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) {
Expand Down