New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage in ES6 import #16
Comments
Technically, this repository isn’t setup for consumption as an ES module in environments that support ES modules natively because it uses implicit file extensions in import paths. For example, in index.js, it says: export {default as hexbin} from "./src/hexbin"; But to be valid ES, it should say: export {default as hexbin} from "./src/hexbin.js"; This will be fixed in a future version (across all of the D3 modules). I mention this because the ability to consume this library as an ES module therefore currently requires you to use a nonstandard build tool such as Rollup or webpack. You must configure this tool to observe the The first is to import the library as a namespace: import * as d3Hexbin from "d3-hexbin";
const hexbin = d3Hexbin.hexbin(); The second is to import individual symbols: import {hexbin as Hexbin} from "d3-hexbin";
const hexbin = Hexbin(); Since this library only has one export ( |
Really appreciate the details here. Im not prepared to roll my own D3, but I can see it might be valuable to do so, but I've wasted enough life energy on webpack and yarn etc.... In the meantime, I just copied hexbin.js elsewhere, changed "default" to
then then:
This might be bad, but its working. Thanks as always. |
Hey @mbostock was there ever an update on this, or should we continue with the |
@mbostock @NicholasCanova I second this. Is the above method mentioned still the way to do it? |
How to import this as an ES6 import? Happy to have it renamed (I dont need to have it in d3. namespace , I just want it in my project. Ive tried:
import * as d3hexbin from "d3-hexbin";
import { hexbin } as d3hexbin from "d3-hexbin";
import d3hexbin from "d3-hexbin/src/hexbin";
import * as d3hexbin from "d3-hexbin/src/hexbin";
import * as hexbin from "d3-hexbin";
I got sankey working with this:
import * as d3Sankey from "d3-sankey";
But no matter how I import this, im getting an error that it is not a function Hope you can help. - D
The text was updated successfully, but these errors were encountered: