question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mischniccommented, Feb 13, 2018

But I do find it confusing that the behaviour of a function (XHR request) is different, just by using ParcelJs

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.

1reaction
mischniccommented, Feb 13, 2018

I had this problem as well (fetching an exotic data file). Solved it with a custom dev server:

const Bundler = require('parcel-bundler')
const express = require('express')

let bundler = new Bundler('src/index.htm')
let app = express()

app.use('/api', express.static('.'));

app.use(bundler.middleware())

app.listen(Number(process.env.PORT || 1234))

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asynchronous Asset Loading - Unreal Engine Documentation
In this example, ItemList is a TArray< TSoftObjectPtr<UGameItem> > that was modified by designers in the editor. The code iterates that list, converts...
Read more >
Loading CSV data from Cloud Storage | BigQuery
Describes how to load CSV data from Cloud Storage to BigQuery. ... You cannot include both compressed and uncompressed files in the same...
Read more >
How to download a local CSV file from a vue.js webpage?
I received the following error when I tried to run this code with a CSV-file: "./src/assets/example.csv Module parse failed: Unexpected token (1 ...
Read more >
Import process for CSV and spreadsheet files - IBM
You can import data from comma-separated values (CSV) and spreadsheet (XLS and XLSX) files into folders and modules in an RM project.
Read more >
Static data load - Sim Innovations Wiki
static_data_load is used to get load static data from a JSON, CSV or text file located in the resources folder.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found