Skip to content

A local-first personal finance app

[AI] Fix navigator is not defined error in @actual-app/api for Node.js environments (#7202)

Matiss Janis Aboltins328b36f1244e
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.