Unverified Commit 925f8a94 authored by Joseph's avatar Joseph Committed by GitHub

fix: find root dir on fs root (#82590)

Attempt at fixing from our side:
https://github.com/vercel/next.js/issues/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 https://github.com/vercel/next.js/issues/82577 - a way for them
to get unblocked is to use a `WORKDIR`. More details on that issue
thread.

---------
Co-authored-by: 's avatarLuke Sandberg <lukesandberg@users.noreply.github.com>
parent fdbe6767
...@@ -23,21 +23,25 @@ export function findRootDir(cwd: string) { ...@@ -23,21 +23,25 @@ export function findRootDir(cwd: string) {
const lockFiles = [lockFile] const lockFiles = [lockFile]
while (true) { while (true) {
const nextDir = dirname(dirname(lockFiles[lockFiles.length - 1])) const lastLockFile = lockFiles[lockFiles.length - 1]
const newLockFile = findRootLockFile(nextDir) const currentDir = dirname(lastLockFile)
const parentDir = dirname(currentDir)
if (newLockFile) { // dirname('/')==='/' so if we happen to reach the FS root (as might happen in a container we need to quit to avoid looping forever
lockFiles.push(newLockFile) if (parentDir === currentDir) break
} else {
break const newLockFile = findRootLockFile(parentDir)
}
if (!newLockFile) break
lockFiles.push(newLockFile)
} }
// Only warn if not in a build worker to avoid duplicate warnings // Only warn if not in a build worker to avoid duplicate warnings
if (typeof process.send !== 'function' && lockFiles.length > 1) { if (typeof process.send !== 'function' && lockFiles.length > 1) {
const additionalLockFiles = lockFiles const additionalLockFiles = lockFiles
.slice(0, -1) .slice(0, -1)
.map((str) => '\n * ' + str) .map((str) => `\n * ${str}`)
.join('') .join('')
if (process.env.TURBOPACK) { if (process.env.TURBOPACK) {
...@@ -61,5 +65,5 @@ export function findRootDir(cwd: string) { ...@@ -61,5 +65,5 @@ export function findRootDir(cwd: string) {
} }
} }
return dirname(lockFile) return dirname(lockFiles[lockFiles.length - 1])
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment