dc-js / dc.js

Multi-Dimensional charting built to work natively with crossfilter rendered with d3.js
Apache License 2.0
7.42k stars 1.8k forks source link

d3-collection dependency missing (es module usage) #1822

Closed nomego closed 3 years ago

nomego commented 3 years ago

I created a sample open-wc app at https://github.com/nomego/dc-owc to highlight some ES6 issues with dc.js

First off is that just by doing import { BarChart } from 'dc' I get an error:

Error while transforming node_modules\dc\src\core\d3compat.js: Could not resolve import "d3-collection".                                                         import "d3-collection".

  1 | import {event, mouse, pointer} from 'd3-selection';
> 2 | import {nest} from 'd3-collection';
    |                    ^
  3 | import {groups} from 'd3-array';
  4 |
  5 | // d3v6 has removed `d3.mouse` in favor of `d3.pointer`

So the d3-collection dep is missing from dc.js 4.2.5 but mandatory

gordonwoodhull commented 3 years ago

@kum-deepak can answer this better, but dc.js doesn't depend on d3-collection, which was removed from d3@6. This module is attempting to detect whether d3@5 or d3@6 is active and won't call nest in the latter case. It is expecting non-existent imports to yield null.

Perhaps we need better support for users doing their own transpilation.

nomego commented 3 years ago

@gordonwoodhull Well even though it's not specified in package.json, using the es6 modules approach, it's an unconditional import statement dependency, so it's technically a dependency for the es6 module approach as the code is designed right now. There's not a strict need to transpile either, since es6 modules are supported natively in the browser. The reason it's being handled by the server is because it's a bare import without and import map. Either it should be added as a package.json dep, imported conditionally or import removed altogether.

kum-deepak commented 3 years ago

Yes, it indeed would cause issues. Let me see how to resolve it.

nomego commented 3 years ago

Thanks! The dev ux of modern web app development with es modules is amazing and the tree shaking has huge potential in the dc.js/crossfilter/d3js setup. I'll gladly compare my example bundles when this is sorted out if you're interested.