1

I am trying to load a local CSV file with papaparse to extract it's content in a Vue3 application.

When I try something like:

let myTest = Papa.parse("@/assets/data/postcodes.csv", {
            delimiter: ",",
            header: true
        });

I get a blank response as if the filepath is wrong. However, if I try importing the file directly with Vue3, so I can pass it to the papaparse method, like this:

import myFile from "@/assets/data/postcodes.csv"

...

let myTest = Papa.parse(myFile, {
            delimiter: ",",
            header: true
        });


I get this error:

ERROR in ./src/assets/data/postcodes.csv 3:5

Module parse failed: Unexpected token (3:5)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| Suburb,Postcode
| Condobolin,2877
> Lake Cargelligo,2672
| Murrin Bridge,2672
| West Wyalong,2671

What is the correct way to reference a local csv file in the asset directory? I assume my file path is correct because of the error.

It hasn't been an issue loading other local assets like images and icons.

tanbog
  • 600
  • 9
  • 28

0 Answers0