Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to import Papaparse

I have a Svelte/Js/Vite app and need to import Papaparse. It’s installed as npm install papaparse and is present in the package.json.

When I import it as import * as Papa from "papaparse";, methods are not visible in the IDE (i.e. parse()) and the following error is shown:

error loading dynamically imported module. This could be due to syntax errors or importing non-existent modules. (see errors above)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

When I import it as import {Papa} from "papaparse";, methods are visible in the IDE, but there s a message

Cannot resolve symbol ‘Papa’

and it anyway doesn’t work in a browser with the same error.

What is the proper way to import and what is the reason for these problems.

>Solution :

I think you need to import it this way since it’s a default exported member:

import Papa from "papaparse";

// the name does not really matter. You can name it whatever you want
// as you're basically saying:
// import { default as Papa } from "papaparse"

// So, you can do it like this too:
// import Mama from "papaparse";

If you’d like to learn more about why, I’d recommend reading this article:
https://www.digitalocean.com/community/tutorials/understanding-modules-and-import-and-export-statements-in-javascript

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading