Get a peek at our latest innovations at Sanity Product Day on Dec 8th →

DOMParser is not defined at defaultParseHtml

3 replies
Last updated: Dec 3, 2020

Hi again! Ive been trying to use

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: 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 
 that parses the html into a DOMParser compatible model / API.

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 Get the most out of your content is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Free to get started, and pay-as-you-go on all plans. Find out more.