Since you're using D3 v5, the pattern described in that answer (which is 6 years old) doesn't work anymore: unlike previous versions, which used XMLHttpRequest, the new version uses promises.
That alone qualifies your question as a duplicate. However, I'm writing this answer because there is an important piece of code missing in your question: the piece that adds the header row.
So, since this is v5, this is the pattern you have to use:
d3.text("data.csv").then(function(data){
//....
})
Inside the callback, you have to add the first row:
data = "foo,bar,baz\n" + data;
Then, you can parse it, using d3.csvParse
:
var newData = d3.csvParse(data);
Because we can't use d3.text
in the S.O. snippet, here is a bl.ocks with the demo: https://bl.ocks.org/GerardoFurtado/8849016b91b41ae463408c747417af95/8b299a22639621ae7619628a5b10fb9257783b8d