Skip to content
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

node import #3511

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
})();
```