Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
docs: document ELECTRON_RUN_AS_NODE leak breaking Electron launches
Elian Doran5ab021282f47
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.mdindex c2e993faa6..7ff1965fe9 100644--- a/.github/copilot-instructions.md+++ b/.github/copilot-instructions.md@@ -241,6 +241,8 @@ Tools are defined using `defineTools()` in `apps/server/src/services/llm/tools/`10. **Attribute inheritance can be complex** - When checking for labels/relations, use `note.getOwnedAttribute()` for direct attributes or `note.getAttribute()` for inherited ones. Don't assume attributes are directly on the note.+11. **`ELECTRON_RUN_AS_NODE` leak crashes Electron launches** - Shells spawned by Electron-based tools (the VS Code extension host, AI coding agents running inside it) often inherit `ELECTRON_RUN_AS_NODE=1`. With it set, launching the desktop app (`pnpm desktop:start`, `pnpm --filter desktop start-prod`) crashes with `TypeError: Not running in an Electron environment!` because `require("electron")` resolves to the npm stub's path string instead of the built-in module. Unset the variable before launching: `Remove-Item Env:ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue` (PowerShell) or `unset ELECTRON_RUN_AS_NODE` (bash).+## MCP Server- Trilium exposes an MCP (Model Context Protocol) server at `http://localhost:8080/mcp`, configured in `.mcp.json`- The MCP server is **only available when the Trilium server is running** (`pnpm run server:start`)diff --git a/CLAUDE.md b/CLAUDE.mdindex f63eed48ee..895fd89e19 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -222,6 +222,7 @@ SQLite via `better-sqlite3`. SQL abstraction in `packages/trilium-core/src/servi- Electron-only features should check `isElectron()` from `apps/client/src/services/utils.ts` (client) or `utils.isElectron` (server)- **`@electron/remote` is removed** — do not use it. All renderer↔main communication goes through the preload bridge.- **Spurious `electron.app is undefined` error** — when running Electron-based apps (`pnpm desktop:start`, `pnpm edit-docs:edit-docs`, etc.), the console may print `TypeError: Cannot read properties of undefined (reading 'commandLine')` from `apps/desktop/src/main.ts` (the `app.commandLine.appendSwitch("disable-http-cache")` line). This is **not a real failure** — the app runs correctly. Do not try to fix it, guard it, or investigate electron initialization order unless the user explicitly raises it as a bug.+- **`ELECTRON_RUN_AS_NODE` leak crashes Electron launches** — shells spawned by Electron-based tools (the VS Code extension host, AI coding agents running inside it) often inherit `ELECTRON_RUN_AS_NODE=1`. With it set, launching the desktop app (`pnpm desktop:start`, `pnpm --filter desktop start-prod`, `electron dist`) crashes at startup with `TypeError: Not running in an Electron environment!` (thrown by `electron-is-dev`, because `require("electron")` resolves to the npm stub's path string instead of the built-in module). This is an environment problem, not an app bug — unset the variable before launching: `Remove-Item Env:ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue` (PowerShell) or `unset ELECTRON_RUN_AS_NODE` (bash).Three inheritance mechanisms:1. **Standard**: `note.getInheritableAttributes()` walks parent tree