Skip to content

Commit 1f8abf1

Browse files
committed
Turbopack fix Next.js package not found panic
joshhannaford/pack-3980-error-turbopackinternalerror-nextjs-package-not-found
1 parent 8b7f937 commit 1f8abf1

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { dirname } from 'path'
22
import findUp from 'next/dist/compiled/find-up'
3+
import * as Log from '../build/output/log'
34

45
export function findRootLockFile(cwd: string) {
56
return findUp.sync(
@@ -17,6 +18,30 @@ export function findRootLockFile(cwd: string) {
1718
}
1819

1920
export function findRootDir(cwd: string) {
20-
const lockFile = findRootLockFile(cwd)
21+
let lockFile = findRootLockFile(cwd)
22+
if (!lockFile) return undefined
23+
24+
let lockFiles = [lockFile]
25+
while (lockFile) {
26+
const nextDir = dirname(dirname(lockFile))
27+
const newLockFile = findRootLockFile(nextDir)
28+
29+
if (newLockFile) {
30+
lockFiles.push(newLockFile)
31+
lockFile = newLockFile
32+
} else {
33+
break
34+
}
35+
}
36+
37+
if (lockFiles.length > 1) {
38+
Log.warnOnce(
39+
`Warning: Found multiple lockfiles. Consider removing the lockfiles at ${lockFiles
40+
.slice(0, lockFiles.length - 1)
41+
.map((str) => '\n * ' + str)
42+
.join('')}\n`
43+
)
44+
}
45+
2146
return lockFile ? dirname(lockFile) : undefined
2247
}

packages/next/src/server/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ function assignDefaults(
699699
dset(result, ['turbopack', 'root'], result.outputFileTracingRoot)
700700
}
701701

702-
// use the closest lockfile as tracing root
702+
// use the highest level lockfile as tracing root
703703
if (!result?.outputFileTracingRoot || !result?.turbopack?.root) {
704704
let rootDir = findRootDir(dir)
705705

packages/next/src/telemetry/detached-flush.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { PHASE_DEVELOPMENT_SERVER } from '../shared/lib/constants'
99
// this process should be started with following arg order
1010
// 1. mode e.g. dev, export, start
1111
// 2. project dir
12+
// 3. root dir
1213
;(async () => {
1314
const args = [...process.argv]
1415
let dir = args.pop()

0 commit comments

Comments
 (0)