Registry / devops / d3-fetch

d3-fetch

JSON →
library3.0.1jsnpmunverified

d3-fetch is a D3 module providing convenient parsing on top of the Fetch API for loading and parsing text, JSON, CSV, TSV, and XML files. Version 3.0.1 is the latest stable release, with no active development since 2021. It is part of the D3 v6/v7 ecosystem, replacing the older d3-request module. Differentiators include built-in support for common data formats, row conversion functions for DSV files, and compatibility with modern JavaScript modules and UMD bundles. Requires Node >=12.

npm install d3-fetch
INSTALL
IMPORT
SIG · D3-FETCH
D
d3-fetch
devopsjavascriptv3.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

d3
import * as d3 from 'd3-fetch'
const d3 = require('d3-fetch')
ESM-only since v3; CommonJS require is not supported. Use ESM import or use the UMD bundle for legacy environments.
csv
import { csv } from 'd3-fetch'
import d3 from 'd3-fetch'; d3.csv()
Named exports are available; default export is an object containing all functions.
json
import { json } from 'd3-fetch'
Use named import for individual functions to reduce bundle size.
text
import { text } from 'd3-fetch'
import { fetch } from 'd3-fetch'
The function is named 'text', not 'fetch'.

Demonstrates loading text, CSV, and JSON files using async/await with the three main functions.

import { csv, json, text } from 'd3-fetch'; async function loadData() { // Load a text file const content = await text('/data/hello.txt'); console.log('Text:', content); // Load and parse a CSV file const rows = await csv('/data/data.csv'); console.log('CSV rows:', rows); // Load and parse a JSON file const data = await json('/data/data.json'); console.log('JSON:', data); } loadData().catch(console.error);
Debug
Known issues
breakingv3 is ESM-only and no longer supports CommonJS require()
fix
Use ES module import (import) or switch to the UMD bundle for legacy environments.
affects: >=3.0.0
deprecatedThe d3-fetch module replaces d3-request; d3-request is deprecated.
fix
Replace d3.xhr, d3.text, etc. with the corresponding d3-fetch functions.
affects: >=3.0.0
gotchaThe csv() and tsv() functions require d3-dsv as a peer dependency; not including it will cause runtime errors.
fix
Ensure d3-dsv is installed (npm install d3-dsv).
affects: *
gotchaAll fetch functions return Promises; must be awaited or used with .then().
fix
Use await or .then() to handle the promise.
affects: *
gotchaWhen using a row conversion function with csv() or dsv(), the function must be the third argument; passing it as second argument incorrectly sets init.
fix
Pass init (optional) before row: csv(url, init, row) not csv(url, row).
affects: *
Errors
Common errors & fixes
Cannot find module 'd3-dsv'
d3-dsv is a required peer dependency not installed.
fix
npm install d3-dsv
d3.csv is not a function
CommonJS require returns an object with default export; may need to use .default or use ESM import.
fix
Use import { csv } from 'd3-fetch' instead of const d3 = require('d3-fetch').
Unhandled Promise Rejection: TypeError: Failed to fetch
The URL is invalid or the server returned an error (e.g., CORS).
fix
Ensure the URL is correct and the server supports CORS or use a proxy.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
d3-dsvrequiredUsed for parsing CSV/TSV files
Agent activity
6 hits · last 30 days
node
6
Resources
d3-fetch — npm install d3-fetch · libregistry