Error using jquery-csv: $.csv is undefined
Javascript has nice tool to read and transform csv data, with handy api but with unexpected inconvenience as well.
Recently in one web project I had to convert csv data to javascript objects.
Quick DuckDuckGo research has shown me library which suits my needs: jquery-csv.
I did everything the same way as in official demo, but exception $.csv is undefined
kept blocking me.
My IDE was able to go to declaration without any problems, still browser was unable to got it.
Solutions
Wait till document is ready
The only solution which I found on the internet was to wait till document is ready.
Unfortunately this was not my case, I already did it.
Check libraries load order
Finally, comparing my code with demo line by line, I found the solution.
I had jquery-csv import after usual jQuery. So all I had to do was moving <script src="jquery-csv.js"></script>
line after
<script src="jquery-3.4.0.min.js"></script>
. That’s because this library tries to follow jQuery api, which seems to be convenient idea,
but practice shows that it has big disadvantage - jQuery deletes or mutates library namespace.
Summary
That’s it, but coming to this point took me some time and internet was not helpful back then, so I decided to share this solution. It might be helpful for people stuck in the same situation :)
Stay up to date!
Get all the latest & greatest posts
delivered straight to your inbox