Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isomorphic-dompurify not working with Remix #8628

Open
joaoguidev opened this issue Jan 29, 2024 · 1 comment
Open

Isomorphic-dompurify not working with Remix #8628

joaoguidev opened this issue Jan 29, 2024 · 1 comment

Comments

@joaoguidev
Copy link

joaoguidev commented Jan 29, 2024

Reproduction

https://stackblitz.com/~/github.com/joaoguidev/RemixDompurify

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900H
    Memory: 4.35 GB / 15.67 GB
  Binaries:
    Node: 18.18.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (121.0.2277.83)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @remix-run/cloudflare: ^2.5.1 => 2.5.1
    @remix-run/cloudflare-pages: ^2.5.1 => 2.5.1
    @remix-run/css-bundle: ^2.5.1 => 2.5.1
    @remix-run/dev: ^2.5.1 => 2.5.1
    @remix-run/react: ^2.5.1 => 2.5.1

Used Package Manager

npm

Expected Behavior

Not get the error below when using Isomorphic-dompurify :
service core:user:worker: Uncaught ReferenceError: window is not defined at c77tsl6ez28.js:29540:22 in node_modules/isomorphic-dompurify/browser.js at c77tsl6ez28.js:82:50 at c77tsl6ez28.js:30604:43

Actual Behavior

Isomorphic-dompurify does not work with Remix because it seems Remix is trying to use the browser entry point from package.json on server.
This problem is listed as a known issue on the Isomorphic-dompurify repository and refer to the issue #214

@sergiodxa
Copy link
Member

The error means the library is trying to use the browser version, probably because Cloudflare picks the browser one instead of the Node one, and since it's not Node this is correct.

If you check their browser build, they just require this other package https://www.npmjs.com/package/dompurify and try to find them from window first. They could just stop trying to find it globally in window and instead just use ESM, but if they don't want to fix this on their side you could skip them and import dompurify yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants