Skip to content

Commit f62a920

Browse files
1 parent 5af8842 commit f62a920

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/backend/fileutils/getProjectRoot.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
22
import fs from 'fs';
3+
import { fileURLToPath } from 'url'; // Explicitly import fileURLToPath.
34

45
let memoizedRoot = null;
56

@@ -8,16 +9,18 @@ function getProjectRoot() {
89
return memoizedRoot;
910
}
1011

11-
let currentDir = path.dirname(new URL(import.meta.url).pathname);
12-
12+
// Convert import.meta.url to a file path
13+
const currentFilePath = fileURLToPath(import.meta.url);
14+
let currentDir = path.dirname(currentFilePath);
15+
1316
while (currentDir !== path.parse(currentDir).root) {
1417
if (fs.existsSync(path.join(currentDir, 'package.json'))) {
1518
memoizedRoot = currentDir;
1619
return memoizedRoot;
1720
}
1821
currentDir = path.dirname(currentDir);
1922
}
20-
23+
2124
throw new Error('Unable to find the project root containing package.json');
2225
}
2326

0 commit comments

Comments
 (0)