Kcnarf / d3-voronoi-map

D3 plugin which computes a map (one-level treemap) based on a Voronoi tesselation
BSD 3-Clause "New" or "Revised" License
91 stars 14 forks source link

'default' is not exported #16

Open louislugas opened 2 years ago

louislugas commented 2 years ago

I want to try this code on svelte REPL, and after I write

import { voronoiMapSimulation } from 'd3-voronoi-map'

it shows warning:

'default' is not exported by https://unpkg.com/d3-array@3.1.1/src/index.js, imported by https://unpkg.com/d3-weighted-voronoi@1.1.2/build/d3-weighted-voronoi.js

because I use REPL, so I didn't use npm install for dependencies

Kcnarf commented 2 years ago

after lurking around the import API, can you try

import { voronoiMapSimulation as d3VoronoiMapSimulation } from 'd3-voronoi-map"

and use the alias d3VoronoiMapSimulation in your code ?

louislugas commented 2 years ago

You can see it in my REPL here: https://svelte.dev/repl/d3847fb950b54cdca2868aaab2bd7872?version=3.49.0

both of them still report the same error 🥺

Kcnarf commented 2 years ago

The error states the issue is that d3-array (used by d3-weighted-voronoi, in turn used by d3-voronoi-map) has not any default export. And that's the case. So the error makes sence.

BUT, What I don't understand is why the error is raised. The source code does not ~import default from d3-array~ : d3-weighted-voronoi source only import {extent as d3Extent} from d3-array (https://github.com/Kcnarf/d3-weighted-voronoi/blob/1d3684d6292ea314b7a07a65506b363d45d83009/src/d3-weighted-voronoi.js#L1).

Moreover, the error is not raised when I copy-paste the code obtained from https://unpkg.com/browse/d3-weighted-voronoi@1.1.3/build/d3-weighted-voronoi.js (url displayed is the error message when import d3-vorono-map).

Below are some tries & comments I did on svelte.dev :

<script>

    // ERROR 'default' is not exported by https://unpkg.com/d3-array@3.2.0/src/index.js, imported by https://unpkg.com/d3-weighted-voronoi@1.1.3/build/d3-weighted-voronoi.js
    // import { weightedVoronoi as d3weightedVoronoi } from 'd3-weighted-voronoi';

    // importing specific API from d3-array works fine
    // import { extent } from 'd3-array'

    // ERROR 'default' is not exported by https://unpkg.com/d3-array@3.2.0/src/index.js, imported by ./App.svelte
    // d3-array hasn't any default export, hence the understandable error
    // import d3Array from 'd3-array'

    // factory skeleton (made by Rollup from source) of build/d3-weighted-voronoi works fine
    /* (function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('d3-polygon')) :
  typeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-polygon'], factory) :
  (factory((global.d3 = global.d3 || {}),global.d3,global.d3));
}(this, function (exports,d3Array,d3Polygon) {
        true
    }))
    */

    // copying the entire https://unpkg.com/d3-weighted-voronoi@1.1.3/build/d3-weighted-voronoi.js works fine

    // ERROR 'default' is not exported by https://unpkg.com/d3-array@3.2.0/src/index.js, imported by https://unpkg.com/d3-weighted-voronoi@1.1.3/build/d3-weighted-voronoi.js
    // same error with on-demand import
    // import('d3-weighted-voronoi').then( ()=> {true})

</script>

<h1>Hello!</h1>
Kcnarf commented 2 years ago

Also, can you check https://github.com/sveltejs/svelte/issues/2962#issuecomment-500249691