Search code examples
javascriptangularpapaparse

Papa Parse single column error Unable to auto-detect delimiting character; defaulted to ','


I have a csv where only one column exists and I am using Papa Parse library to parse the csv. I receive the following error Unable to auto-detect delimiting character; defaulted to ','

Since it is only a single column it is not comma separated value. I tried to set delimeter config property to auto delimiter: "", but still the same problem


Solution

  • CSV is far from being a standard. Even though there's a RFC, the format itself pre-dates the document, which anyway starts with:

    It does not specify an Internet standard of any kind.

    Plus CSV is often created by quick and dirty tools that couldn't care less about interoperability. In particular, even a well-known tool like Microsoft Excel generates different file formats depending on the regional settings of the computer where it runs!

    All this means that, in order to parse a CSV file, you need to determine the exact file format and, in particular, which character is being used to separate different columns: despite the fact that the C in CSV stands for comma, it's just as common to find semicolons. Depending on the software capabilities options include:

    • Tell the program
    • Let the program guess

    In your case, guessing goes wrong because you only have one column, thus there aren't any separators in the file that the library can find. The error message is confusing, though, because it suggests there's a default separator (,) but it isn't actually defaulting to it.

    Since guessing is neither possible nor needed, just tell it explicitly to use ,:

    {
        delimiter: "",  // auto-detect <--------- We don't want this!
        newline: "",    // auto-detect
        quoteChar: '"',
        header: false,
        dynamicTyping: false,
        preview: 0,
        encoding: "",
        worker: false,
        comments: false,
        step: undefined,
        complete: undefined,
        error: undefined,
        download: false,
        skipEmptyLines: false,
        chunk: undefined,
        fastMode: undefined,
        beforeFirstChunk: undefined,
        withCredentials: undefined
    }