diff --git a/packages/slidev/node/cli.ts b/packages/slidev/node/cli.ts index 51519b9e9d..cc33038252 100644 --- a/packages/slidev/node/cli.ts +++ b/packages/slidev/node/cli.ts @@ -204,7 +204,7 @@ cli.command( let publicIp: string | undefined if (remote) - publicIp = await import('public-ip').then(r => r.publicIpv4()) + publicIp = await resolvePublicIp() lastRemoteUrl = printInfo(options, port, base, remote, tunnelUrl, publicIp) if (open) @@ -223,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({ @@ -278,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()) + const publicIp = await resolvePublicIp() if (publicIp) console.log(`\n${dim(' Public IP: ')} ${blue(publicIp)}\n`) })