backend: Fix import of sanitize-html #193
Loading…
Reference in a new issue
No description provided.
Delete branch "Michcio/FoundKey-0x7f:import-sanitize-html"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm not sure how it managed to work so far, but the function is the default
export, using the namespace like a function should not have worked,
maybe something under the hood was correcting it back
The packages NPM page says:
The said option is not set in
packages/backend/tsconfig.json
.The package's NPM page also states that TypeScript support is close to none, and the issue that caused it was over a year ago. From the thread it seems the maintainers just accepted whatever helped somebody on the thread and slapped it on the top of the readme. I tried just now building a minimal repro case of it. What I do know is:
sanitize-html
does not have"type": "module"
inpackage.json
, while we do. This is known to cause NodeJS to handle the imports and exports differently, for the package specifically, but this is independent for each package.tsconfig.json
implores tsc to resolve modules through node, and to generate code in the model of esnext ("type": "module"
) style modules.When I build a tiny project that just runs
sanitizeHtml("aaa")
with those two facts included in configs, the code only works if I remove* as
. Because when we're in"type": "module"
, and tsc knows that we are, NodeJS handles the difference in module model behind the scenes completely. When there is a discrepancy between what tsc and what NodeJS think the module model to be, only then is there a need for a workaround like the* as
.So with that in mind I believe esModuleInterop is not actually necessary, here or elsewhere, in otherwise well configured TS projects with
"type": "module"
.Why, I've ran a
main
branch test instance just now, enabled email wherever I could in the admin panel, and what I get in the logs when submitting an abuse report isbecause apparently this is and has been an untested code path? Idk. When I remove
as *
the error disappears (and turns into an SMTP error, because of course I didn't configure SMTP, but it passes the sanitization part).Ok yeah I also checked and there is a type error about this when building the backend as is, which is fixed by this patch.