From 328b36f1244ec5505bafc6990dd336e176ad7185 Mon Sep 17 00:00:00 2001 From: Matiss Janis Aboltins Date: Sun, 15 Mar 2026 08:13:55 +0000 Subject: [PATCH] [AI] Fix navigator is not defined error in @actual-app/api for Node.js environments (#7202) * [AI] Fix navigator is not defined error in @actual-app/api for Node.js environments Add platform.api.ts to provide Node.js-safe defaults for platform detection, which the API's Vite config resolves before the browser-only platform.ts. Also guard navigator access in environment.ts isElectron() function. Fixes #7201 https://claude.ai/code/session_015Xz2nHC12pNkADGjGZnSXd * Add release notes for PR #7202 --------- Co-authored-by: Claude Co-authored-by: github-actions[bot] --- packages/loot-core/src/shared/environment.ts | 5 ++++- packages/loot-core/src/shared/platform.api.ts | 7 +++++++ upcoming-release-notes/7202.md | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 packages/loot-core/src/shared/platform.api.ts create mode 100644 upcoming-release-notes/7202.md diff --git a/packages/loot-core/src/shared/environment.ts b/packages/loot-core/src/shared/environment.ts index 8a6d021107..50992b19b1 100644 --- a/packages/loot-core/src/shared/environment.ts +++ b/packages/loot-core/src/shared/environment.ts @@ -11,7 +11,10 @@ export function isNonProductionEnvironment() { } export function isElectron() { - if (navigator.userAgent.indexOf('Electron') >= 0) { + if ( + typeof navigator !== 'undefined' && + navigator.userAgent.indexOf('Electron') >= 0 + ) { return true; } return false; diff --git a/packages/loot-core/src/shared/platform.api.ts b/packages/loot-core/src/shared/platform.api.ts new file mode 100644 index 0000000000..1d2588eae8 --- /dev/null +++ b/packages/loot-core/src/shared/platform.api.ts @@ -0,0 +1,7 @@ +export const isPlaywright = false; + +export const OS: 'windows' | 'mac' | 'linux' | 'unknown' = 'unknown'; +export const env: 'web' | 'mobile' | 'unknown' = 'unknown'; +export const isBrowser: boolean = false; + +export const isIOSAgent = false; diff --git a/upcoming-release-notes/7202.md b/upcoming-release-notes/7202.md new file mode 100644 index 0000000000..d8accd6c2e --- /dev/null +++ b/upcoming-release-notes/7202.md @@ -0,0 +1,6 @@ +--- +category: Bugfixes +authors: [MatissJanis] +--- + +Fix navigator access error in Node.js environments by adding existence checks and defaults.