👀 See Sanity in action: Watch product demo now →

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 – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in