From dfe6da063e05ae18091ca486792d16bed549ee74 Mon Sep 17 00:00:00 2001 From: Bryan <91551702+blondon1@users.noreply.github.com> Date: Mon, 11 Aug 2025 10:13:04 -0700 Subject: [PATCH] fix: add Node.js version check for capacitor cmds (#801) Resolves #787. Prevents crashes when running capacitor commands on a system with an incompatible (older) Node.js version. --------- Co-authored-by: Will Chen --- src/ipc/handlers/capacitor_handlers.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ipc/handlers/capacitor_handlers.ts b/src/ipc/handlers/capacitor_handlers.ts index 928eb9b..8c53e69 100644 --- a/src/ipc/handlers/capacitor_handlers.ts +++ b/src/ipc/handlers/capacitor_handlers.ts @@ -40,6 +40,20 @@ export function registerCapacitorHandlers() { async (_, { appId }: { appId: number }): Promise => { const app = await getApp(appId); const appPath = getDyadAppPath(app.path); + + // check for the required Node.js version before running any commands + const currentNodeVersion = process.version; + const majorVersion = parseInt( + currentNodeVersion.slice(1).split(".")[0], + 10, + ); + + if (majorVersion < 20) { + // version is too old? stop and throw a clear error + throw new Error( + `Capacitor requires Node.js v20 or higher, but you are using ${currentNodeVersion}. Please upgrade your Node.js and try again.`, + ); + } return isCapacitorInstalled(appPath); }, );