From 7b9a9fe179fae1d21cdc9f3643f87560b5c9cec3 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..7d7412839 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 {}; } /** @@ -151,7 +155,7 @@ export function parseURL(url) { * @returns {string} */ export function getPath(url) { - return parseURL(url).pathname; + return typeof document !== 'undefined' ? parseURL(url)?.pathname : ''; } /**