diff --git a/packages/docusaurus/src/server/brokenLinks.ts b/packages/docusaurus/src/server/brokenLinks.ts index a07e5ec056d9..31080b58cc24 100644 --- a/packages/docusaurus/src/server/brokenLinks.ts +++ b/packages/docusaurus/src/server/brokenLinks.ts @@ -130,14 +130,17 @@ async function filterExistingFileLinks({ allCollectedLinks: Record; }): Promise> { // not easy to make this async :'( - function linkFileDoesNotExist(link: string): boolean { + function linkFileExists(link: string): boolean { const filePath = `${outDir}/${removePrefix(link, baseUrl)}`; - const exists = fs.existsSync(filePath); - return !exists; + try { + return fs.statSync(filePath).isFile(); // only consider files + } catch (e) { + return false; + } } return mapValues(allCollectedLinks, (links) => { - return links.filter(linkFileDoesNotExist); + return links.filter((link) => !linkFileExists(link)); }); }