Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

Hi again! Ive been trying to use `@sanity/block-tools` and i keep getting this error: ```ReferenceError: DOMParser is not defined at defaultParseHtml (***/studio/node_modules/@sanity/blo...

6 replies
Last updated: Dec 3, 2020

Hi again! Ive been trying to use

@sanity/block-tools
and i keep getting this error:
ReferenceError: DOMParser is not defined
    at defaultParseHtml (***/studio/node_modules/@sanity/block-tools/lib/HtmlDeserializer/helpers.js:173:35)
Happens on my own code as well as the example code provided in the packages readme, here:
https://github.com/sanity-io/sanity/blob/next/packages/%40sanity/block-tools/README.md I am running the script through
sanity exec
Im puzzled
😭

Dec 3, 2020, 12:16 PM

The HTML-deserialization is done by default by the browser's native DOMParser. On the server side you can give the function 
parseHtml
 that parses the html into a DOMParser compatible model / API.
https://github.com/sanity-io/sanity/tree/next/packages/%40sanity/block-tools#parsehtml

Dec 3, 2020, 12:18 PM

if you're running it on the server, you need to npm/yarn install some DOM parser like jsdom and use that

Dec 3, 2020, 12:19 PM

That makes complete sense! And you just got rid of my error - thanks a ton! đŸ»

Dec 3, 2020, 12:20 PM

The HTML-deserialization is done by default by the browser's native DOMParser. On the server side you can give the function 
parseHtml
 that parses the html into a DOMParser compatible model / API.
https://github.com/sanity-io/sanity/tree/next/packages/%40sanity/block-tools#parsehtml

Dec 3, 2020, 12:18 PM

if you're running it on the server, you need to npm/yarn install some DOM parser like jsdom and use that

Dec 3, 2020, 12:19 PM

That makes complete sense! And you just got rid of my error - thanks a ton! đŸ»

Dec 3, 2020, 12:20 PM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.