Comments (4)
Actually, there may be a general page about how to import and use these d3 mini modules for different environments and each module reference can point to that general page at the beginning. Instead of a seperate page, section Supported Environments on d3 wiki homepage can be also used.
from d3-collection.
es6 and es2015 modules will not work with d3 because d3 has chosen to use rollup instead.
you can either use rollup or make all the text substitutions yourself using a script or manually. I use a perl one-liner because I dislike rollup and the extra dependencies were breaking between node 8 and node 10. it is unbelievably strange that this is necessary but I also haven't been supporting a kitchen sink of module loaders.
import * as d3 from "./node_modules/d3-something/index.js"
which has content like export {default as something} from './src/thing'
. because these files do not use the natively supported syntax with a full relative path (it's missing the actual file extension), it won't work without rollup or whatever making these corrections. multiple popular projects have made this same decision to require extra modules to work properly and forego native support.
see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
from d3-collection.
es6 and es2015 modules will not work with d3 because d3 has chosen to use rollup instead.
Yes and no.
Rollup takes ES modules as input, and you can consume those ES modules directly (unbundled) without Rollup if you’re in an environment that supports ES modules.
But Rollup uses a “relaxed” definition of ES modules in regards to the import specifiers (the paths). Part of this is out of necessity—the ES module specification explicitly disallows bare import specifiers; there’s no way to import … from "d3-array"
to load a dependency from node_modules. (That doesn’t apply to d3-collection since it has no dependencies.) But also the D3 modules also omit the .js
extension on most import specifiers.
For example, unpkg supports this relaxed definition of ES modules and rewrites the import specifiers to absolute paths, making them compatible with browsers and the specification:
<script type="module">
import * as d3 from "https://unpkg.com/d3-collection?module";
console.log(d3);
</script>
from d3-collection.
Regarding the missing file extensions perhaps consider a comment about this scenario in Nodejs: https://youtu.be/M3BM9TB-8yA?t=837
And please note that supporting Rollup via unpkg effectively and currently makes these a requirement to use d3 with imports.
from d3-collection.
Related Issues (19)
- Fix prototype.constructor.
- d3.map could take an optional value accessor function? HOT 1
- ES6 Collections. HOT 2
- d3.group convenience function? HOT 3
- Support natural sorting of keys. HOT 5
- sortValues after rollup HOT 2
- Feature request HOT 1
- value/values on rollup function HOT 2
- d3.nest reformats a Date object to a string HOT 1
- Nest: individual key sorting HOT 1
- d3.nest retains node properties after rollup HOT 4
- Feature Request - same level nesting by multiple key HOT 1
- Custom key, values field names for the nest() HOT 5
- Why does d3.nest.map prepend a prefix? HOT 4
- nest.rollup should create {key, value} for leaf entries. HOT 9
- Add nest.count or nest.visit? HOT 1
- Mutable nests? HOT 1
- Support string as accessor? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-collection.