Skip to content

Commit

Permalink
node import
Browse files Browse the repository at this point in the history
in reply to #3469 (comment)
  • Loading branch information
Fil committed Jun 25, 2021
1 parent 13460d0 commit 2cd6823
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions README.md
Expand Up @@ -63,12 +63,20 @@ import * as d3 from "d3";

In Node:

The previous `import` works if your package is of "type": "module". An alternative is to load the d3 module or its submodules asynchronously:

```js
const d3 = require("d3");
(async function() {
const d3 = await import("d3");
console.log(d3);
})();
```

You can also require individual modules and combine them into a `d3` object using [Object.assign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign):

```js
const d3 = Object.assign({}, require("d3-format"), require("d3-geo"), require("d3-geo-projection"));
(async function() {
const d3 = Object.assign({}, await import("d3-format"), await import("d3-geo"), await import("d3-geo-projection"));
console.log(d3);
})();
```

0 comments on commit 2cd6823

Please sign in to comment.