【问题标题】:Importing D3 using NPM?使用 NPM 导入 D3?
【发布时间】:2020-09-25 09:13:14
【问题描述】:

我在安装 npm 后无法正确导入 d3。通过 d3 下载或 per the documentation 的脚本标签,导入似乎成功了,但这对我来说似乎有点反模式,因为我习惯于使用 npm 或 yarn 等工具导入我的依赖项。

运行 npm install d3 并尝试导入库时,我在打开 index.html 后在浏览器控制台中看到以下错误

js1.js

import d3 from 'd3';

const greetings = function js1(greeting)
{
    console.log("Hello from js1" + greeting);
    const selectedelement = d3.select(some_element)
    ...

}

index.html

<head>
    <script src="js1.js" type="text/javascript"></script>
</head>
<div>
    <script language="javascript">
        greetings("HALLO");
    </script>
...

package.json

...
  "dependencies": {
    "d3": "^6.2.0"
  }

package-lock.json

...
  "dependencies": {
...
    "d3": {
      "version": "6.2.0",
...

【问题讨论】:

    标签: javascript html d3.js


    【解决方案1】:

    试试这个。

    import * as d3 from "d3";
    

    the document中查看更多信息

    【讨论】:

      猜你喜欢
      • 2016-07-21
      • 2020-05-08
      • 2021-03-02
      • 2017-10-22
      • 2017-10-06
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 2019-08-21
      相关资源
      最近更新 更多