@@ -2,7 +2,15 @@ import path from 'path'
2
2
import { app } from 'electron'
3
3
import { DESKTOP_DATA_DIR , DESKTOP_DEV_DATA_DIR } from '@quiet/common'
4
4
import { __nodeConsoleLogger } from '@quiet/logger'
5
- import dotenvx from '@dotenvx/dotenvx'
5
+ // Defer loading to runtime to avoid Jest resolver issues with ESM subpath exports
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ let dotenvx : any
8
+ try {
9
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
10
+ dotenvx = require ( '@dotenvx/dotenvx' )
11
+ } catch ( e ) {
12
+ // If not available/resolveable in test, leave undefined; guarded use below
13
+ }
6
14
__nodeConsoleLogger . info ( 'Environment variables' , JSON . stringify ( process . env , null , 2 ) )
7
15
8
16
const isDev = process . env . NODE_ENV === 'development'
@@ -13,12 +21,12 @@ if (isDev || process.env.DATA_DIR) {
13
21
14
22
try {
15
23
const pathProd = path . join . apply ( null , [ process . resourcesPath , '.env' ] )
16
- const loadedEnvVarsresult = dotenvx . config ( { path : pathProd } )
17
- __nodeConsoleLogger . info ( 'Loaded env vars' , JSON . stringify ( loadedEnvVarsresult . parsed , null , 2 ) )
18
- if ( loadedEnvVarsresult . error ) {
19
- __nodeConsoleLogger . error ( `Error occurred while loading main envs` , loadedEnvVarsresult . error )
20
- } else {
21
- // save env file contents to a variable for passthrough
24
+ if ( dotenvx ? .config ) {
25
+ const loadedEnvVarsresult = dotenvx . config ( { path : pathProd } )
26
+ __nodeConsoleLogger . info ( 'Loaded env vars' , JSON . stringify ( loadedEnvVarsresult . parsed , null , 2 ) )
27
+ if ( loadedEnvVarsresult . error ) {
28
+ __nodeConsoleLogger . error ( `Error occurred while loading main envs` , loadedEnvVarsresult . error )
29
+ }
22
30
}
23
31
} catch ( e ) {
24
32
__nodeConsoleLogger . error ( `Error occurred while loading main envs` , e )
0 commit comments