Skip to content

Commit e363c51

Browse files
authored
fix npm root issues on Next.js deploy (#6372)
* increase npm root timeout to 5s * memoize npm root * changelog
1 parent f6bbbcb commit e363c51

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix "Could not find the next executable" on Next.js deployments (#6372)

src/frameworks/utils.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import { BUILD_TARGET_PURPOSE, RequestHandler } from "./interfaces";
2424
// the import statement into a require
2525
const { dynamicImport } = require(true && "../dynamicImport");
2626

27-
const NPM_ROOT_TIMEOUT_MILLIES = 2_000;
27+
const NPM_ROOT_TIMEOUT_MILLIES = 5_000;
28+
const NPM_ROOT_MEMO = new Map<string, string>();
2829

2930
/**
3031
* Whether the given string starts with http:// or https://
@@ -222,9 +223,19 @@ function scanDependencyTree(searchingFor: string, dependencies = {}): any {
222223
}
223224

224225
export function getNpmRoot(cwd: string) {
225-
return spawnSync("npm", ["root"], { cwd, timeout: NPM_ROOT_TIMEOUT_MILLIES })
226+
let npmRoot = NPM_ROOT_MEMO.get(cwd);
227+
if (npmRoot) return npmRoot;
228+
229+
npmRoot = spawnSync("npm", ["root"], {
230+
cwd,
231+
timeout: NPM_ROOT_TIMEOUT_MILLIES,
232+
})
226233
.stdout?.toString()
227234
.trim();
235+
236+
NPM_ROOT_MEMO.set(cwd, npmRoot);
237+
238+
return npmRoot;
228239
}
229240

230241
export function getNodeModuleBin(name: string, cwd: string) {

0 commit comments

Comments
 (0)