wa0x6e / cal-heatmap

Cal-Heatmap is a javascript charting library to create a time-series calendar heatmap
http://cal-heatmap.com
MIT License
2.69k stars 290 forks source link

Commonjs export is not working #440

Open nkemcels opened 8 months ago

nkemcels commented 8 months ago

I have a module which depends on cal-heatmap. In this module, I'm importing cal-heatmap via esm

import CalHeatmap from "cal-heatmap";
...

I'm bundling this module with webpack using the umd target and because I do not want the bundle size of the module to be large, I've externalize cal-heatmap. Externalizing cal-heatmap causes it to be referenced in the module using the commonjs syntax, require("cal-heatmap");

But when I use the exported module in my project, the reference to cal-heatmap breaks the project. After hours of hair-pulling, I noticed that the global d3, d3-selection, d3-color and d3-fetch externalized in cal-heatmap is the root source of the issue. They are all undefined when imported with commonjs syntax

FallingEpiphany commented 8 months ago

change it into import CalHeatmap from '@labzh/cal-heatmap'