Closed rondonjon closed 2 years ago
Turns out the problem is caused by snowpack. Filing a new bug there.
Hello! I know this issue was closed -- but I'm running into the same problem @rondonjon described, when using the plugin-node-resolve plugin for Rollup. It apparently uses the Node resolution algorithm to sort out dependencies and seems to have the exact same problem with css-select import as was raised in this issue. Curious if you've got any insight here, or specific concern about rewriting the commonJS imports.
May I suggest to change the
css-select
import inhtml.ts
fromto
?
It seems that
css-select
is only exporting a CommonJS build, in which case the bundler/compiler must decide how to resolve the import. At least for Snowpack (and possibly Rollup, which Snowpack uses internally) this seems to cause problems.Bundlers which follow the ESM specification strictly will resolve the
import
statement in the first snippet (version 5.0.0) to the default export of the CommonJS module, which is in this case theselectAll
function of thecss-select
module.{ selectAll, selectOne }
are then handled as a destructuring assignment on the expected object, i.e. they will refer toselectAll.selectAll
andselectAll.selectOne
and resolve toundefined
. This doesn't cause immediate problems, but will raise runtime errors when the functions are invoked later in the code.The second snippet / suggested change refers explicitly to the "exported namespace" of the CommonJS module, so that
selectAll
andselectOne
will resolve to the named exports (the functions) as intended.