Skip to content

Commit f6d81d6

Browse files
committed
handle both ESM and CJS ?
1 parent aeecd11 commit f6d81d6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/inference/src/snippets/python.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ interface TemplateParams {
3131
// Helpers to find + load templates
3232

3333
const rootDirFinder = (): string => {
34-
let currentPath = path.normalize(import.meta.url).replace("file:", "");
34+
let currentPath =
35+
typeof import.meta !== "undefined" && import.meta.url
36+
? path.normalize(new URL(import.meta.url).pathname) /// for ESM
37+
: __dirname; /// for CJS
3538

3639
while (currentPath !== "/") {
3740
if (pathExists(path.join(currentPath, "package.json"))) {

0 commit comments

Comments
 (0)