使用async / await并得到“无法在'response'主体流上执行'json'的操作被锁定为eval”错误

时间:2019-11-05 23:53:39

标签: javascript es6-promise

const repoBarGraph = async () => {
    d3.selectAll("#bar-vis > *").remove();
    d3.select(".main-vis-container > #tip").remove();

    const repoNames = await fetchRepos(userInputValue.value);
    const days = [
      "Sunday",
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday"
    ];
    const reposWeekCommits = await Promise.all(
      repoNames.map(async repoName => {
        const repoStats = await fetchRepoStats(userInputValue.value, repoName);
        let dayCommitArr = Array(7).fill(0);
        repoStats.map(repoStat => {
          repoStat.days.map((day, i) => (dayCommitArr[i] += day));
        });
        debugger;
        return dayCommitArr;
      })
    );

    let sumArr = Array(7).fill(0);
    reposWeekCommits.map(repoDayCommits =>
      repoDayCommits.map((repoDayCommit, i) => (sumArr[i] += repoDayCommit))
    );

    let barData = [];

    for (let i = 0; i < days.length; i++) {
      barData.push({ day: days[i], commits: sumArr[i] });
    }
    console.log(barData);
    ...

每当我尝试运行此代码时,它都会给我JSON输入意外的结尾。那是因为“无法在'response'主体流上执行'json'锁定为eval”错误。但是我看不到我在哪里多次使用我的承诺或如何解决它。提前谢谢你的帮助。

0 个答案:

没有答案