remarkablemark/html-react-parser

Resolution error when using TypeScript with `moduleResolution` set to `node16` or `nodenext`

wojtekmaj opened this issue · 5 comments

Expected Behavior

html-react-parser to resolve correctly when using TypeScript with moduleResolution set to node16 or nodenext (effectively: in pure ESM environment).

Actual Behavior

html-react-parser is not resolved correctly:

https://arethetypeswrong.github.io/?p=html-react-parser%405.1.2

This also causes the types to be non-functional in VSCode:

image

Steps to Reproduce

Create a project using TypeScript with moduleResolution set to node16 or nodenext.
Create a file with the following content:

import parse from 'html-react-parser';

you'll already see, when you hover over parse bit, that types are not loaded correctly.

Reproducible Demo

Environment

  • Version: 5.0.7
  • Platform: Node.js
  • Browser: not applicable
  • OS: macOS Sonoma 14.2.1

Keywords

Relates to remarkablemark/html-dom-parser#669

Can you verify if this issue is resolved in the release?

"Are the Types Wrong?" looks good: https://arethetypeswrong.github.io/?p=html-react-parser%405.1.4

Hi @remarkablemark, thanks for this. It's a definite improvement since the types are now working correctly. But (unlike in html-dom-parser, which doesn't use any imports beyond index.(m)js files), module resolution inside is still broken, as extensionless imports are being used.

I'm more than happy to fix that, but I believe we'd like to have an architectural decision made in remarkablemark/html-dom-parser#671 to avoid breaking changes :)

Makes sense, we can discuss there

wondering why was this closed @remarkablemark @wojtekmaj ?

facing the same issue

"html-react-parser": "5.1.10",

"moduleResolution": "Node16",
image

it seems while your export maps are correct from TS POV, under the hood they are not as you're mixing ESM with CJS

image

When we provide a proper EMS for default export like following everything works as expected

image

image

@Hotell do you mind opening a new issue? Also, if you can provide a reproducible example, I can take a look as well.