【问题标题】:d3.js loading a csv throwing a TypeError in Chrome and something [native code] in Safarid3.js 加载 csv 在 Chrome 中抛出 TypeError 并在 Safari 中抛出 [native code]
【发布时间】:2017-09-28 20:47:52
【问题描述】:

所以我在 7 月份推出了一个 d3 项目,它正在运行。我今天把它拉下来更新,在运行npm install 后,我收到来自d3.csv() 的错误

以下...

d3.csv('js/data/data1.csv', (returnedData) => {
    console.log('RETURNEDDATA', returnedData);
});

在 Chrome 的控制台中,它会追踪一个包含 10 个对象的数组,这些对象具有正确的列标题,但值都是 NaN,另外还有一个额外的属性读取...

1: TypeError: Failed to execute 'fetch' on 'Window': Failed to parse URL from //localhost:80js/data/data1.csv

在 Safari 中,我得到了类似的东西,但它显示为...

0 {[native code]: "initializeFetchRequest@[native code]", 3P%: NaN, AST: NaN, BPM: NaN, FG%: NaN, …}
1 {[native code]: "[native code]"}
2 {[native code]: "fetch@[native code]"}
3 {[native code]: "_onFinish@http://localhost:3000/js/scripts-bundle.js:18:27206"}
4 {[native code]: "http://localhost:3000/js/scripts-bundle.js:18:26091"}
5 {[native code]: "emit@http://localhost:3000/js/scripts-bundle.js:12:30954"}
6 {[native code]: "finishMaybe@http://localhost:3000/js/scripts-bundle.js:18:13349"}
7 {[native code]: "endWritable@http://localhost:3000/js/scripts-bundle.js:18:13432"}
8 {[native code]: "end@http://localhost:3000/js/scripts-bundle.js:18:16918"}
9 {[native code]: "end@http://localhost:3000/js/scripts-bundle.js:18:29326"}
10 {[native code]: "send@http://localhost:3000/js/scripts-bundle.js:19:13018"}
11 {[native code]: "send@http://localhost:3000/js/scripts-bundle.js:8:4724"}
12 {[native code]: "http://localhost:3000/js/scripts-bundle.js:21:3849"}
13 {[native code]: "mightThrow@http://localhost:3000/js/scripts-bundle.js:15:6588"}
14 {[native code]: "http://localhost:3000/js/scripts-bundle.js:15:7221"}

知道是什么原因造成的吗?我已经从 4.9 更新了。?到 4.10.2 没有成功。

【问题讨论】:

    标签: javascript csv d3.js


    【解决方案1】:

    将您的package.json 文件更改为4.10.0,再次运行npm installnpm update,问题似乎消失了。

    看起来这是最新版本的 D3 中的依赖项的问题——即在包 d3-request 版本 1.0.6 中发生了一些事情。如果回滚到使用d3-request早期版本的D3版本4.10.0,也就是1.0.5,貌似没有这个问题。

    我在d3-request 存储库中提出了一个问题,所以希望这可以在下一个补丁中修复。随意在那里发表您自己的评论,以便每个人都可以看到这是一个影响多人的问题:https://github.com/d3/d3-request/issues/29

    如果它们与我所描述的不同,请在此处添加您自己的详细信息。

    【讨论】:

      【解决方案2】:

      显然,当您使用 NPM 安装 d3 时会发生一些事情。清除 d3 并从 CDN 导入库解决了我的问题。显然,NPM 安装的依赖项之一正在搞乱 URL。注意Failed to parse URL from //localhost:80js/data/data1.csv中的:80js

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-18
        • 2021-02-28
        • 1970-01-01
        • 2011-06-24
        • 2017-10-12
        • 1970-01-01
        相关资源
        最近更新 更多