Skip to content

Commit 81f6126

Browse files
committed
fix(desktop-main): lazy-load electron-store to avoid requiring electron binary in tests
electron-store v11 imports electron at the top of its index.js, so any require('electron-store') fails in plain-Node environments where the electron binary hasn't been downloaded (e.g. integration test CI). Switch the import to `import type` (type-only, no runtime effect) and use createRequire inside createStore(), which is only called when readIsElectron() returns true. Plain-Node paths continue to use the in-memory Map fallback without ever loading electron-store. Refs #144
1 parent b132b30 commit 81f6126

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

app/packages/desktop-main/src/services/ElectronStoreService.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { createRequire } from 'node:module';
12
import { Injectable } from '@nestjs/common';
2-
import Store from 'electron-store';
3+
import type Store from 'electron-store';
34
import { logger } from '../logger.js';
5+
6+
const _require = createRequire(import.meta.url);
47
import { SafeStorageService } from './SafeStorageService.js';
58

69
/**
@@ -147,7 +150,10 @@ export class ElectronStoreService {
147150
* directory.
148151
*/
149152
protected createStore(): Store<AppStoreSchema> {
150-
return new Store<AppStoreSchema>({ name: 'electron-store' });
153+
// Lazy-require so electron-store (which imports electron at the top level)
154+
// is only loaded inside a real Electron process, never in plain-Node tests.
155+
const StoreClass = (_require('electron-store') as { default: typeof Store }).default;
156+
return new StoreClass({ name: 'electron-store' });
151157
}
152158

153159
/**

0 commit comments

Comments
 (0)