Next 13/14 - Isomorphic DOMPurify - Build Error #58142
Replies: 3 comments 36 replies
-
Hi, Without much knowledge into the matter, it seems to me that the problem is that, this library is doing a strange check... If you copy their code, and tweak it a bit: "use client";
function resolveDOMPurify() {
const isClientSide = typeof process === "undefined";
return isClientSide ? console.log("client") : console.log("server");
}
resolveDOMPurify();
export const Button = () => {
return (
<button type="button" >
+1
</button>
);
}; It'll log server on the client. I am not sure in what context you use it, but that's more or less the problem. I am gonna drop something from the Apollo GraphQL Docs:
As for your issue, perhaps defer usage of this library to the client side, by using next/dynamic, or hiding it behind a boolean that is set on the client only, for example within a use-effect. This of course has implications for the initial HTML string that you'll send to your clients. |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, The isomorphic-dompurify maintainer is here. I do think the browser.js is for some reason used here because the code which causes the error is: var ti=window.DOMPurify||(window.DOMPurify=Vl().default||Vl()); and the content of the browser.js is: module.exports = window.DOMPurify || (window.DOMPurify = require('dompurify').default || require('dompurify')); which I think are almost identical. |
Beta Was this translation helpful? Give feedback.
-
same with SvelteKit deployed on Cloudflare Pages |
Beta Was this translation helpful? Give feedback.
-
Summary
isomorphic-dompurify version - 1.9.0
Node version - 18.18.0
Next.js version - 13.5.4 (also reproduced with Next 14)
React version - 18.2.0
I am importing my company's React component library that makes use of Isomorphic DOMPurify.
No issues when using it in a client-side app.
However, when running yarn build in my Next.js project I am getting ReferenceError: window is not defined and the path in the logs points to the following line of code: var ti=window.DOMPurify||(window.DOMPurify=Vl().default||Vl());
In the issue for the package - kkomelin/isomorphic-dompurify#228 - it was suggested that possibly Next treats the browser field in the package.json as a server entry point. Could this be the culprit?
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions