htmlparser2 icon indicating copy to clipboard operation
htmlparser2 copied to clipboard

ESM build attempts to import CJS build modules from 'entities'

Open barneycarroll opened this issue 1 year ago • 2 comments

Parser.ts hardcodes an import identifier pointing to the CJS build of entities:

https://github.com/fb55/htmlparser2/blob/b3ce38c015a2881b9d655400b526ed9bc0043403/src/Parser.ts#L2

This breaks pure ESM parsing of the ESM build. I'm not sure what a conventional solution would look like, but assume there ought to be an 'abstract' identifier path which would resolve by parsing package.json depending on environment?

barneycarroll avatar Mar 13 '24 14:03 barneycarroll

@barneycarroll were you able to address this?

maxgurewitz avatar Jun 04 '24 00:06 maxgurewitz

@maxgurewitz the closed source project I was using that depended on htmlparser2 (via linkedom) uses a custom JavaScript parser, so the issue was worked around there. I know various open source bundlers and runtime hacks allow inter-operating CJS & ESM, but I couldn’t recommend a generic solution.

barneycarroll avatar Jun 04 '24 08:06 barneycarroll