From 2cd6823a8b8aa24f65c4a375e5ae85afa409dc10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Fri, 25 Jun 2021 15:48:43 +0200 Subject: [PATCH] node import in reply to https://github.com/d3/d3/issues/3469#issuecomment-866273720 --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d6e2700794a2..e9fb38af93e89 100644 --- a/README.md +++ b/README.md @@ -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); +})(); ```