From 622c63a3ad0d721e4be562d7a5206170d7eaddea Mon Sep 17 00:00:00 2001 From: Pavel Milkevich Date: Wed, 2 Oct 2024 16:53:00 +0200 Subject: [PATCH] Error importing HtmlReactParser in index.cjs file #44 --- src/RichText.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/RichText.tsx b/src/RichText.tsx index d991053..a44077d 100644 --- a/src/RichText.tsx +++ b/src/RichText.tsx @@ -2,7 +2,7 @@ import type {RichTextParams} from './types' // Converts an HTML string to one or more React elements -import HTMLReactParser from 'html-react-parser'; +import * as parser from 'html-react-parser'; // Replaces "matching" domNodes import {createReplacer} from './RichText/createReplacer'; @@ -26,7 +26,9 @@ export function RichText>({ return { data.processedHtml - ? HTMLReactParser(data.processedHtml, { + /* try parser.default.default first because import is wrapped with __toesm() in cjs files + * for node compatibility, which adds default export resulting in parser.default.default */ + ? (parser.default['default'] || parser.default)(data.processedHtml, { replace: createReplacer({ ...rest, // These should be last, so they can't be overridden