Nuxt's plugins/modules system is extremely complicated and as such I've not been able to accomplish this very simple task, even after looking at some other answers here on SO. I've installed the NPM package csv-parse (found here), then I created a file in my project's plugins directory named csv-parse.js, in which I put the following code:
import Vue from 'vue';
import CsvParse from 'csv-parse';
Vue.use(CsvParse);
Then I added { src: "~/plugins/csv-parse", mode: "client" } to the plugins array in my nuxt.config.js (I only need to use this package client-side).
As far as Nuxt's documentation and the other SO answers will have you believe, you should now be able to use this package globally in your components, but no one cares to show how to use it in your component. Here's what I've tried:
// @/components/Hospitals/Crud.vue
...
<script>
export default {
methods: {
parseFileData() {
console.log('parser:', CsvParser); // ReferenceError: CsvParser is not defined
console.log('parser:', $CsvParser); // ReferenceError: $CsvParser is not defined
console.log('parser:', this.CsvParser); // undefined
console.log('parser:', this.$CsvParser); // undefined
}
}
}
</script>
...
Can someone please clear the mystery of how to globally use custom NPM packages in a Nuxt project?