-
-
Notifications
You must be signed in to change notification settings - Fork 760
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
3.2.0 seems to cause a build error in Angular/React: An export assignment cannot be used in a module with other exported elements. #1018
Comments
I have this problem too but in a React app 🤔 I can confirm I don't have this issue on v3.1.7 |
same issue here |
a bit more info on this, if we modify the file + export { type Config, type Hook, type HookName, type RemovedAttribute, type RemovedElement, type UponSanitizeAttributeHook, type UponSanitizeAttributeHookEvent, type UponSanitizeElementHook, type UponSanitizeElementHookEvent, type WindowLike, type DOMPurify };
- export { type Config, type Hook, type HookName, type RemovedAttribute, type RemovedElement, type UponSanitizeAttributeHook, type UponSanitizeAttributeHookEvent, type UponSanitizeElementHook, type UponSanitizeElementHookEvent, type WindowLike, type DOMPurify, _default as default };
- export = _default; then it works. However, this change was actually modified by this DOMPurify/scripts/fix-cjs-types.js Lines 10 to 14 in 2cf6e25
in short, it looks like the "types": "./dist/purify.es.d.cts",
"exports": {
".": {
"import": {
"types": "./dist/purify.es.d.mts",
"default": "./dist/purify.es.mjs"
},
"require": {
"types": "./dist/purify.es.d.cts",
"default": "./dist/purify.cjs.js"
}
}
}, So is the |
Good question, cc @reduckted and @ssi02014 maybe? 🙂 |
It's necessary to make the types correct according to With that script:
Without that script:
Whether there's another way to fix it, I don't know. 😕 |
@ghiscoding, @sumitramanga, @aky-wtag Can you provide a reproduction of the error? I've created an Angular application and using |
@reduckted I got the problem on my open source project Angular-Slickgrid, I rolled back the change but basically just cloning the project and updating the package.json to 3.2 again, then run dev scripts will reproduce the error.
Like I said in my previous comment, simply copying the // clone-dts.mjs
import { readFileSync, writeFileSync } from 'node:fs';
writeFileSync('dist/index.d.cts', readFileSync('dist/index.d.ts')); |
Hi, I got the following errors with DOMPurify 3.2.0
|
@asamuzaK that's a different and probably separate error, you're probably missing the dev dependencies |
@ghiscoding |
@reduckted Thanks Dave! The following is my build log. I see that I need
|
I think that you problem is something different and is potentially what I saw yesterday when I tried in a React app and that was caused by React itself. For example if you take this error from the console log 00:54:16 ERROR in C:/app/node_modules/dompurify/dist/purify.cjs.d.ts(245,9): if you then go to the source code and hover What I don't understand though in here, DOMPurify, is why import type { TrustedHTML } from 'trusted-types/lib';
sanitize: (html: string) => string | TrustedHTML; This would fix React since this would explicitly say |
@reduckted so I tested a bit more and you're right at this point the patch that you have seems to be the only way to get ATTW working. However my Angular really doesn't like it, also I thought it might be because I'm using the legacy WebPack build but even with the new esbuild the error shows up. I also found that I'm falling on the CJS Types because my tsconfig is configured with I think the only way to make it all work would be to use EDIT I got a working build with EDIT 2 @reduckted I found a very simple fix and push a PR #1022 and finally my build is working and everyone is happy :) |
fix: ignore export assign cannot be used in module TS error, fixes #1018
Hey everyone :) The PRs have been merged, many thanks! Are we now good for another release? |
I think so. At the very least, the changes that have been made should get it working for more people. |
Re Update: |
And one more. |
@cure53 Yes please 😃 |
3.2.1 is out, thanks everyone :) https://github.com/cure53/DOMPurify/releases/tag/3.2.1 |
Background & Context
I tried to upgrade to latest v3.2.0 that drops the need for the
@types/dompurify
which is awesome, however my Angular build is now failing with this error (you can see the error in my CI workflow failure)If we browse to the CJS dist bundle from unpkg, we can see that it's the last line of the file export that it doesn't seem to like. I don't fully understand the problem but it might be due to trying to export DOMPurify twice? Though again I'm not entirely sure, see this Stack Overflow answer for that error
Bug
Also another possible issue that I found on top of what is described above, is that I was a bit surprised that it picked up the CJS (CommonJS) build instead of the expect ESM dist. Taking a look at the
package.json
, it is most probably because the CJSrequire
is the first export to appear, however it should really be theimport
that comes first and make therequire
a fallback (2nd) which is the inverse of what is currently set. Note that I could provide a PR for the correct order but I'm not really that will fix the 1st error aboveDOMPurify/package.json
Lines 29 to 38 in 2cf6e25
We can see the correct order in NodeJS conditional exports
Input
n/a
Given output
n/a
Expected output
no build error
Feature
n/a
The text was updated successfully, but these errors were encountered: