apostrophecms / sanitize-html

Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance
MIT License
3.68k stars 349 forks source link

Problems running applications bundled using Vite #553

Closed truesteps closed 1 year ago

truesteps commented 2 years ago

To Reproduce

Step by step instructions to reproduce the behavior:

  1. Install sanitize-html with
  2. Try run project with Vite dev
  3. Open page
  4. See error

Expected behavior

A working build with vite

Describe the bug

Seems like V-sanitize implements some functions from the path node library and path uses process.platform, meanwhile Vite doesn't send the process into context, it uses import.meta. The two attached screenshots showcase the issue, as well as the problem line.

Details

Version of Node.js: v16.11.1

Server Operating System: Docker Ubuntu

Additional context:

I'm using sanitize-html within a package called v-sanitize for vue and I wanted to rewrite it to Vue 3 and Vite support.

Screenshots Screenshot 2022-07-07 at 10 06 16 Screenshot 2022-07-07 at 10 06 10

truesteps commented 2 years ago

I updated 2nd step, since Vite only uses esmodules on dev, this only breaks when bundling app for development. When bundling for production, Vite uses rollup, so production builds work as expected.

boutell commented 1 year ago

This looks like a bundling / frontend build issue at the postcss level. You could open a ticket with postcss, or it may be an issue with the way your bundling for frontend use works, but it's not something that can be resolved within sanitize-html.

boutell commented 1 year ago

Excuse me, I meant to say "within sanitize-html."