Can't load static asset (CSV file for instance) asynchronously
See original GitHub issue🐛 bug report
I normally use d3.tsv, d3.csv or d3.jetpack.loadData to load a CSV, JSON or TSV data static asset asynchronously. For instance the d3.jetpack.loadData (url, function(error, response) {}), the response parameter would normally contain the data file as an object, but now that I use ParcelJs, response only contains the HTML of the current page as an array.
The code below illustrates an example that does work without ParcelJs, but has different behaviour with ParcelJs.
🎛 Configuration (.babelrc, package.json, cli command)
{
"presets": ["env"]
}
{
"name": "",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "parcel index.html",
"build": "parcel build index.js"
},
"repository": {
"type": "git",
"url": "t"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^8.0.0",
"babel-preset-env": "^1.6.1",
"postcss-modules": "^1.1.0",
"posthtml-img-autosize": "^0.1.1",
"standard": "^10.0.3"
},
"dependencies": {
"d3-array": "^1.2.1",
"d3-jetpack": "^2.0.16",
"d3-request": "^1.0.6"
}
}
🤔 Expected Behavior
In the code sample, the expected value of res should be the tsv-file as object.
😯 Current Behavior
In the code sample, the current value of res is the HTML of the current page as an array.
💁 Possible Solution
🔦 Context
I’m trying to load a static asset (CSV, TSV or JSON file) asynchronously. It’s a rather large file, hence the asynchronous loading.
💻 Code Sample
import { tsv } from 'd3-request'
tsv('./data/data.tsv', (err, res) => {
if (err) {
console.error(err)
}
console.log(res)
})
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.5.1 |
| Node | 8.9.4 |
| npm | 5.6.0 |
| Operating System | MacOS High Sierra 10.13.3 |
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)

Top Related StackOverflow Question
To (hopefully) clear this matter up: when a file doesn’t exist, parcel serves
index.html. This is so that client-side-routing on single page apps works.I had this problem as well (
fetching an exotic data file). Solved it with a custom dev server:Something like https://github.com/webpack-contrib/copy-webpack-plugin would be useful. (For example, you can’t require a pdf file.)
EDIT: Is there any documentation that with
fs.readfileSync, the content gets inlined?