Coder Social home page Coder Social logo

Usage in ES6 import about d3-hexbin HOT 4 CLOSED

d3 avatar d3 commented on April 20, 2024
Usage in ES6 import

from d3-hexbin.

Comments (4)

mbostock avatar mbostock commented on April 20, 2024 3

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 module entry point defined in the package.json if you want to be able to import this library using a bare module specifier (and currently that module entry point has an implicit file extension: index instead of index.js). Assuming you have configured your build tool to find the intended entry point, there are two valid styles of imports.

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 (hexbin), I’d probably chose the latter, but it’s up to you.

from d3-hexbin.

NicholasCanova avatar NicholasCanova commented on April 20, 2024 1

Hey @mbostock was there ever an update on this, or should we continue with the import * as d3Hexbin from 'd3-hexbin'; as the method of importing?

from d3-hexbin.

DDDgfx avatar DDDgfx commented on April 20, 2024

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

export function hex() {...}

then
import { hex } from "../location";

then:

var hexmap = hex()...

This might be bad, but its working. Thanks as always.

from d3-hexbin.

skouzini avatar skouzini commented on April 20, 2024

@mbostock @NicholasCanova I second this. Is the above method mentioned still the way to do it?

from d3-hexbin.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.