Would anyone happen to know if DOMpurify is supported when building within Netlify?

Hello all!

Would anyone happen to know if DOMpurify is supported when building within Netlify?

I’ve tried searching the following error but couldn’t find a resolution:

11:19:38 AM: failed Building static HTML for pages - 3.556s
11:19:38 AM: error Building static HTML failed for path "/index/"
11:19:38 AM: > 130 |                                 <div className="intro--richtext" dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(documentToHtmlString(node.intro)) }}></div>
11:19:38 AM:   WebpackError: TypeError: dompurify__WEBPACK_IMPORTED_MODULE_3__.default.saniti  ze is not a function

I’ve made sure to include an .nvmrc file as well in case there was a version issue.

Please let me know if additional information is needed.

Thank you!

1 Like

I don’t know what that is. Certainly we don’t support it magically; you’d have to have it in your package.json or yarn.lock for the appropriate NODE_ENV. Is it listed there?

Thank you for the reply!

I am using DOMpurify in combination with dangerouslySetInnerHtml to sanitize my inputs. It is listed within my package.json and I have an .nvmrc file for Node version control. I’ve also added all the necessary variables needed.

The project builds on our locals but not on Netlify. The build is also successful when we remove DOMpurify.sanitize:

 <div className="intro--richtext" dangerouslySetInnerHTML={{__html: documentToHtmlString(node.intro) }}></div>

The error above is what appears within the Netlify deploy logs.

Hey there! It seems like Webpack and your static site generator are getting snagged on DOMpurify during your site build, but it might be possible to build the site without DOMpurify and then bring it in later. Could you try removing it as a dependency from your package.json and dropping the script tag for the minified library into the index.html file as described here:

And let us know if that works for you?

1 Like