Skip to content

Commit 925f8a9

Browse files
fix: find root dir on fs root (#82590)
Attempt at fixing from our side: #82577 Rather, the issue is that when the project is at the root of the file system - `findRootDir` loops indefinitely, and we keep pushing to the lockFiles found. I also noticed the warning claims we use the last lockfile found, but we return `dirname(lockfile)` - that is the first lock file found. Regardless, when using this project setup: ```console . ├── apps │   └── frontend │   ├── README.md │   ├── next.config.ts │   ├── package.json │   ├── pnpm-lock.yaml │   ├── src │   │   └── app │   │   ├── globals.css │   │   ├── layout.tsx │   │   └── page.tsx │   └── tsconfig.json ├── package.json ├── pnpm-lock.yaml └── pnpm-workspace.yaml ``` Running `pnpm --filter frontend dev` still ends up in panic: `Error [TurbopackInternalError]: Next.js package not found` - Maybe that's still expected :) As for #82577 - a way for them to get unblocked is to use a `WORKDIR`. More details on that issue thread. --------- Co-authored-by: Luke Sandberg <[email protected]>
1 parent fdbe676 commit 925f8a9

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/next/src/lib/find-root.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,25 @@ export function findRootDir(cwd: string) {
2323

2424
const lockFiles = [lockFile]
2525
while (true) {
26-
const nextDir = dirname(dirname(lockFiles[lockFiles.length - 1]))
27-
const newLockFile = findRootLockFile(nextDir)
26+
const lastLockFile = lockFiles[lockFiles.length - 1]
27+
const currentDir = dirname(lastLockFile)
28+
const parentDir = dirname(currentDir)
2829

29-
if (newLockFile) {
30-
lockFiles.push(newLockFile)
31-
} else {
32-
break
33-
}
30+
// dirname('/')==='/' so if we happen to reach the FS root (as might happen in a container we need to quit to avoid looping forever
31+
if (parentDir === currentDir) break
32+
33+
const newLockFile = findRootLockFile(parentDir)
34+
35+
if (!newLockFile) break
36+
37+
lockFiles.push(newLockFile)
3438
}
3539

3640
// Only warn if not in a build worker to avoid duplicate warnings
3741
if (typeof process.send !== 'function' && lockFiles.length > 1) {
3842
const additionalLockFiles = lockFiles
3943
.slice(0, -1)
40-
.map((str) => '\n * ' + str)
44+
.map((str) => `\n * ${str}`)
4145
.join('')
4246

4347
if (process.env.TURBOPACK) {
@@ -61,5 +65,5 @@ export function findRootDir(cwd: string) {
6165
}
6266
}
6367

64-
return dirname(lockFile)
68+
return dirname(lockFiles[lockFiles.length - 1])
6569
}

0 commit comments

Comments
 (0)