1

I'm new in lwc.
I was supposed to export function and import it as a module in lwc,
but when i deploy the JS file which has export function it shows i didn't return a value.

I really don't know which value i should return. Could you please help me?

Here is my utils.js

export function exportCSVFile(headers, totalData, fileTitle){
    
    if(!totalData || !totalData.length) {
        return null
    }
    const jsonObject = JSON.stringify(totalData)
    const result = convertToCSV(jsonObject, headers)
    if(!result){
        return null
    }
    const blob = new Blob([result])
    const exportedFileName = fileTitle? fileTitle+ '.csv': 'export.csv'
    if(navigator.msSaveBlob){
      navigator.msSaveBlob(blob, exportedFileName)

    } else if(navigator.userAgent.match(/iPhone|iPad|iPod/i)){
        const link = window.document.createElement('a')
        link.href = 'data:text/csv;charset=utf-8,' + encodeURI(result);
        link.target = "_blank"
        link.download = exportedFileName
        link.click()
    } else {
        const link = window.document.createElement('a')
        if(link.download !== undefined){
            const url = URL.createObjectURL(blob)
            link.setAttribute("href", url)
            link.setAttribute("download", exportedFileName)
            link.style.visibility="hidden"
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link)
        }      
    }
  
} 

function convertToCSV(objArray, headers){
...
 return str
}

1 Answer 1

1

It sounds like an eslint error, which should not necessarily prevent deployment. Regardless, eslint would complain because you're sometimes returning a value (return null is still returning a value), versus the last line of your function, which does not return a value. Realistically, you should be able to fix this by changing return null to just return.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .