From 38ab823a231926c3dc283a6b5892fab55875d105 Mon Sep 17 00:00:00 2001 From: Syed Ali Abbas Zaidi Date: Fri, 13 Oct 2023 16:02:34 +0500 Subject: [PATCH] fix: href property issue in gatsby build --- src/utils.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/utils.js b/src/utils.js index debd1b1a7..fe46915bc 100644 --- a/src/utils.js +++ b/src/utils.js @@ -138,9 +138,13 @@ export function convertKeyNames(object, nameMap) { * @returns {Object} */ export function parseURL(url) { - const parser = document?.createElement('a'); - parser.href = url; - return parser; + if (typeof document !== 'undefined') { + const parser = document?.createElement('a'); + parser.href = url; + return parser; + } + + return null; } /** @@ -151,7 +155,7 @@ export function parseURL(url) { * @returns {string} */ export function getPath(url) { - return parseURL(url).pathname; + return parseURL(url)?.pathname; } /**