From 86073384bfa0ba855b431fd3af2e5c1a06fa75bf Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Wed, 26 Aug 2026 19:47:50 +0500 Subject: [PATCH 1/2] fix(cli): don't crash when the public IP can't be resolved --- packages/slidev/node/cli.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/slidev/node/cli.ts b/packages/slidev/node/cli.ts index 51519b9e9d..7b0a0d8c02 100644 --- a/packages/slidev/node/cli.ts +++ b/packages/slidev/node/cli.ts @@ -203,8 +203,14 @@ cli.command( } let publicIp: string | undefined - if (remote) - publicIp = await import('public-ip').then(r => r.publicIpv4()) + if (remote) { + try { + publicIp = await import('public-ip').then(r => r.publicIpv4()) + } + catch { + console.log(yellow('\n Could not determine the public IP address.\n')) + } + } lastRemoteUrl = printInfo(options, port, base, remote, tunnelUrl, publicIp) if (open) @@ -278,7 +284,7 @@ cli.command( const code = r.renderUnicodeCompact(lastRemoteUrl!) console.log(`\n${dim(' QR Code for remote control: ')}\n ${blue(lastRemoteUrl!)}\n`) console.log(code.split('\n').map(i => ` ${i}`).join('\n')) - const publicIp = await import('public-ip').then(r => r.publicIpv4()) + const publicIp = await import('public-ip').then(r => r.publicIpv4()).catch(() => undefined) if (publicIp) console.log(`\n${dim(' Public IP: ')} ${blue(publicIp)}\n`) }) From 6bd3463963f4eef872c3148046be72017c336961 Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Wed, 26 Aug 2026 20:00:13 +0500 Subject: [PATCH 2/2] refactor(cli): share the public IP lookup between both call sites --- packages/slidev/node/cli.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/slidev/node/cli.ts b/packages/slidev/node/cli.ts index 7b0a0d8c02..cc33038252 100644 --- a/packages/slidev/node/cli.ts +++ b/packages/slidev/node/cli.ts @@ -203,14 +203,8 @@ cli.command( } let publicIp: string | undefined - if (remote) { - try { - publicIp = await import('public-ip').then(r => r.publicIpv4()) - } - catch { - console.log(yellow('\n Could not determine the public IP address.\n')) - } - } + if (remote) + publicIp = await resolvePublicIp() lastRemoteUrl = printInfo(options, port, base, remote, tunnelUrl, publicIp) if (open) @@ -229,6 +223,15 @@ cli.command( } } + async function resolvePublicIp() { + try { + return await import('public-ip').then(r => r.publicIpv4()) + } + catch { + console.log(yellow('\n Could not determine the public IP address.\n')) + } + } + async function openTunnel(port: number) { const { startTunnel } = await import('untun') const tunnel = await startTunnel({ @@ -284,7 +287,7 @@ cli.command( const code = r.renderUnicodeCompact(lastRemoteUrl!) console.log(`\n${dim(' QR Code for remote control: ')}\n ${blue(lastRemoteUrl!)}\n`) console.log(code.split('\n').map(i => ` ${i}`).join('\n')) - const publicIp = await import('public-ip').then(r => r.publicIpv4()).catch(() => undefined) + const publicIp = await resolvePublicIp() if (publicIp) console.log(`\n${dim(' Public IP: ')} ${blue(publicIp)}\n`) })