@@ -9,6 +9,8 @@ import { teeCommand as tee } from "@/src/commands/tee";
9
9
import { loadEnvironment } from "@/src/utils/get-config" ;
10
10
import { logger } from "@/src/utils/logger" ;
11
11
import { Command } from "commander" ;
12
+ import { fileURLToPath } from "node:url" ;
13
+ import { dirname } from "node:path" ;
12
14
13
15
process . on ( "SIGINT" , ( ) => process . exit ( 0 ) ) ;
14
16
process . on ( "SIGTERM" , ( ) => process . exit ( 0 ) ) ;
@@ -22,10 +24,29 @@ async function main() {
22
24
// Load environment variables, trying project .env first, then global ~/.eliza/.env
23
25
await loadEnvironment ( ) ;
24
26
25
- // read package.json version
26
- const packageJsonPath = path . join ( process . cwd ( ) , "package.json" ) ;
27
- const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , "utf-8" ) ) ;
28
- const version = packageJson . version ;
27
+ // For ESM modules we need to use import.meta.url instead of __dirname
28
+ const __filename = fileURLToPath ( import . meta. url ) ;
29
+ const __dirname = dirname ( __filename ) ;
30
+
31
+ // Find package.json relative to the current file
32
+ const packageJsonPath = path . resolve ( __dirname , "../package.json" ) ;
33
+ console . log ( "packageJsonPath" , packageJsonPath ) ;
34
+
35
+ // Add a simple check in case the path is incorrect
36
+ let version = "0.0.0" ; // Fallback version
37
+ if ( ! fs . existsSync ( packageJsonPath ) ) {
38
+ console . warn (
39
+ "Package.json not found at expected location:" ,
40
+ packageJsonPath ,
41
+ ) ;
42
+ console . warn ( "Using fallback version:" , version ) ;
43
+ } else {
44
+ const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , "utf-8" ) ) ;
45
+ console . log ( "packageJson" , packageJson ) ;
46
+ version = packageJson . version ;
47
+ }
48
+
49
+ console . log ( "version" , version ) ;
29
50
30
51
const program = new Command ( )
31
52
. name ( "eliza" )
0 commit comments