Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encounter "ReferenceError: document is not defined" when call convertFromHTML() on Node.js server side #222

Open
hzhang008 opened this issue May 14, 2023 · 0 comments

Comments

@hzhang008
Copy link

hzhang008 commented May 14, 2023

Hi,

I am trying to use "draft-convert" package on Node.js servide side. When I call convertFromHTML(html) , I got the following error:


ReferenceError: document is not defined
at fallback (/node_modules/draft-convert/lib/util/parseHTML.js:9:13)
at parseHTML (/node_modules/draft-convert/lib/util/parseHTML.js:25:11)
at getChunkForHTML (/node_modules/draft-convert/lib/convertFromHTML.js:458:18)

I followed some online posts to pass DOMBuilder function as a second parameter to convertFromHTML() like the following:


// Define the DOMBuilder function
function DOMBuilder(html) {
const dom = new JSDOM(<!DOCTYPE html><body>${html}</body>);
return dom.window.document.body;
}

// Call convertFromHTML with the DOMBuilder function and required classes
const html = 'Hello Text';
const contentState = convertFromHTML(html, DOMBuilder);

However, I still got the same "document is not defined" error.

Does anyone have the same problem when using this package on Node.js? I am using the latest version of "draft-convert".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant