Closed andreidiaconescu closed 1 year ago
a workaround that worked for me: change import to:
import DOMPurify from 'dompurify';
and add to tsconfig.json
compilerOptions."allowSyntheticDefaultImports": true,
That's likely the way, yes. Is this issue specific to Angular 16?
Closing this as it's unclear what we can do here...
We got the same issue, so adding some info here in case it helps.
Firstly I'm not sure why the reccomended approach is to import * as
since dompurify has a single default export: https://github.com/cure53/DOMPurify/blob/main/dist/purify.es.js#L1662
We import the default import.
When dompurify recently introduced more modern javascript into its default dist/purify.js bundle, babel kicked in and because we use @babel/transform-runtime, it added imports to the purify.js file so that webpack recognised it as a ecmascript module even though it is not - the end result seems to be nothing is exported and the import is undefined.
The fix for us was to tell webpack to resolve to the dist/purify.es.js file and then it worked.
Background & Context
Trying to use DOMPurify.sanitize in an angular 16 application.
Bug
I added to node modules:
I import as recomended:
import * as DOMPurify from 'dompurify';
then i use like this:
Input
any simple text like: "comment 4.2 some comment val"
Given output
i get error in the Chrome browser console:
Expected output
Sanitized text.