Skip to content

Commit e86098d

Browse files
authored
fix(next): use fileURLToPath for cross-platform path resolution (#14877)
Fixes #14880 ## Summary Fixes a bug where `getNextjsVersion()` fails to read the Next.js package.json on Windows systems, causing errors like: Error: ENOENT: no such file or directory, open 'F:\F:\data...\next\package.json'
1 parent 25ef7d1 commit e86098d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/next/src/withPayload/withPayload.utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
import { readFileSync } from 'fs'
29+
import { fileURLToPath } from 'url'
2930

3031
function _parseInt(input: string | undefined): number {
3132
return parseInt(input || '', 10)
@@ -86,7 +87,9 @@ export function getNextjsVersion(): SemVer | undefined {
8687
if (typeof import.meta?.resolve === 'function') {
8788
// ESM environment - use import.meta.resolve
8889
const pkgUrl = import.meta.resolve('next/package.json')
89-
pkgPath = new URL(pkgUrl).pathname
90+
// Use fileURLToPath for proper cross-platform path handling (Windows, macOS, Linux)
91+
// new URL().pathname returns '/C:/path' on Windows which causes path resolution issues
92+
pkgPath = fileURLToPath(pkgUrl)
9093
} else {
9194
// CJS environment - use require.resolve
9295
pkgPath = require.resolve('next/package.json')

0 commit comments

Comments
 (0)