I installed isomorphic-dompurify ^2.15.0
to my Angular 18 SSR application. It builds successfully with the standard DomPurify
code, such as:
import DOMPurify from "isomorphic-dompurify";
DOMPurify.sanitize(dirtyHtml);
But at runtime, you will get the following error:
[vite] Error when evaluating SSR module /main.server.mjs:
|- TypeError: Cannot convert undefined or null to object
at Function.getPrototypeOf (<anonymous>)
at node_modules/whatwg-url/lib/utils.js (C:...angularcache18.2.1vitedeps_ssrisomorphic-dompurify.js:19369:41)
at __require2 (C:...angularcache18.2.1vitedeps_ssrchunk-2FDURXR6.js:51:50)
at node_modules/whatwg-url/lib/URL.js (C:...angularcache18.2.1vitedeps_ssrisomorphic-dompurify.js:22241:17)
at __require2 (C:...angularcache18.2.1vitedeps_ssrchunk-2FDURXR6.js:51:50)
at node_modules/whatwg-url/webidl2js-wrapper.js (C:...angularcache18.2.1vitedeps_ssrisomorphic-dompurify.js:22648:16)
at __require2 (C:...angularcache18.2.1vitedeps_ssrchunk-2FDURXR6.js:51:50)
at node_modules/whatwg-url/index.js (C:...angularcache18.2.1vitedeps_ssrisomorphic-dompurify.js:22662:9)
at __require2 (C:...angularcache18.2.1vitedeps_ssrchunk-2FDURXR6.js:51:50)
at node_modules/jsdom/lib/api.js (C:...angularcache18.2.1vitedeps_ssrisomorphic-dompurify.js:141933:21)
I found a similar, still open, issue here for Angular 15: Build error when using isomorphic-dompurify in angular 15 universal #203.