-
Hello, I am trying to import csv from assets folder into my JS file: import continentsCSV from '../../assets/SixContinentFirst.csv'
import * as d3 from 'd3'
useEffect(() => {
d3.csv(continentsCSV).then(data => console.log(data))
}, []) But I get Back an error: Uncaught SyntaxError: The requested module '/src/assets/SixContinentFirst.csv?import' does not provide an export named 'default' If I try to just pass path like this without importing: useEffect(() => {
d3.csv('../../assets/SixContinentFirst.csv').then(data => console.log(data))
}, []) I get 404 not found error. Here is how my csv file looks:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Install
...and configure Vite to use it: // vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import dsv from '@rollup/plugin-dsv' 👈
export default defineConfig({
plugins: [
vue(),
dsv(), 👈
],
}) Then importing a <script>
// MyComponent.vue
import csv from './filmList.csv'
console.log(csv) // => [{'name':'Parasite','year':'2019','href':'parasite-2019','src':'film-poster/4/2/6/4/0/6/426406-parasite-0-460-0-690-crop.jpg'}]
</script> |
Beta Was this translation helpful? Give feedback.
-
Dose there one solution for |
Beta Was this translation helpful? Give feedback.
-
For those who just want a URL that point to the origin file, append |
Beta Was this translation helpful? Give feedback.
Install
@rollup/plugin-dsv
as a dev dependency:...and configure Vite to use it:
Then importing a
.csv
file would produce the object array, as you were expecting:demo