【问题标题】:fetch is not defined in D3 csv callfetch 未在 D3 csv 调用中定义
【发布时间】:2022-01-18 06:18:24
【问题描述】:

我正在尝试运行 D3 示例,但似乎 d3-fetch 似乎没有导出提取。但是 text.js 可以。我使用 npm 添加了 d3-fetch。 我有点困惑。在 VS Code 中运行它。

这是调用代码:

driving = d3.csv("driving.csv");

来自 text.js:

export default function(input, init) {
  return fetch(input, init).then(responseText);
}

........

ReferenceError: fetch is not defined
    at default (file:///C:/D3Test/node_modules/d3-fetch/src/text.js:7:3)
    at Module.<anonymous> (file:///C:/D3Test/node_modules/d3-fetch/src/dsv.js:7:12)
    at file:///C:/D3Test/scatter.mjs:180:26

【问题讨论】:

    标签: javascript d3.js


    【解决方案1】:
    npm install node-fetch
    

    import fetch from "node-fetch";
    

    如果您在 package.json 中收到错误 "type": "module"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-12
      • 2020-01-19
      • 2017-02-04
      • 1970-01-01
      • 2021-06-23
      • 1970-01-01
      相关资源
      最近更新 更多