diff --git a/.changeset/sixty-chicken-obey.md b/.changeset/sixty-chicken-obey.md new file mode 100644 index 000000000000..be19baace6d8 --- /dev/null +++ b/.changeset/sixty-chicken-obey.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix preview --host in Node.js 18 diff --git a/packages/astro/src/core/messages.ts b/packages/astro/src/core/messages.ts index 6020a45b7b15..3bfcbb61a2b1 100644 --- a/packages/astro/src/core/messages.ts +++ b/packages/astro/src/core/messages.ts @@ -126,13 +126,15 @@ export function resolveServerUrls({ let network: string | null = null; if (networkLogging === 'visible') { - const nodeVersion = Number(process.version.substring(1, process.version.indexOf('.', 5))); const ipv4Networks = Object.values(os.networkInterfaces()) .flatMap((networkInterface) => networkInterface ?? []) .filter( (networkInterface) => networkInterface?.address && - networkInterface?.family === (nodeVersion < 18 || nodeVersion >= 18.4 ? 'IPv4' : 4) + // Node < v18 + ((typeof networkInterface.family === 'string' && networkInterface.family === 'IPv4') || + // Node >= v18 + (typeof networkInterface.family === 'number' && networkInterface.family === 4)) ); for (let { address: ipv4Address } of ipv4Networks) { if (ipv4Address.includes('127.0.0.1')) {