taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.11k stars 107 forks source link

Fix non-default ESM imports #175

Closed heypiotr closed 2 years ago

heypiotr commented 2 years ago

esm/index.js currently does:

import nhp from '../dist/index.js'

This is importing the default export from ../dist/index.js AKA src/index.ts, which is the parse function:

export { default as parse, default } from './parse';
                           ^^^^^^^

... which means when esm/index.js later tries to do this:

export const CommentNode = nhp.CommentNode;

... nhp is actually the parse function, which means nhp.CommentNode is undefined.

nonara commented 2 years ago

Thanks for your submission!

Unfortunately, ESM has caused a lot of confusion and issues for many of us. One of the primary reasons behind this is the fundamentally different way that ESM handles import / export.

The pattern we've followed to enable ESM is a standard technique, as described here: https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1

Please see this comment in a similar PR for more detail on why the syntax we've used is correct:

The thread may also help in getting it working for you. Best of luck!

heypiotr commented 2 years ago

Oh, interesting! Thanks for sharing ❤️