TypeError: Cannot read properties of undefined (reading 'writeFile') at writeFileAsync (xlsx.mjs:24045:13) #2895

Closed
opened 2023-02-26 14:45:22 +00:00 by githubid0719 · 1 comment
function downExcel(data, fileName) {
   import('xlsx').then(({writeFile, utils, writeFileAsync}) => {
    const wb = utils.book_new();
    const ws =  utils.json_to_sheet(data,  {skipHeader: false})
    utils.book_append_sheet(wb, ws);
    writeFileAsync(fileName, wb, ()=> {

    });
   }).catch(err=> {
      console.log('err', err)
   })
}

In the browser environment. When I call the writeFileAsync method to realize the asynchronous export of excel, he threw the following exception. Is it that I call incorrectly? How can I use the writeFileAsync method?

![image](uploading ...)

``` function downExcel(data, fileName) { import('xlsx').then(({writeFile, utils, writeFileAsync}) => { const wb = utils.book_new(); const ws = utils.json_to_sheet(data, {skipHeader: false}) utils.book_append_sheet(wb, ws); writeFileAsync(fileName, wb, ()=> { }); }).catch(err=> { console.log('err', err) }) } ``` In the browser environment. When I call the writeFileAsync method to realize the asynchronous export of excel, he threw the following exception. Is it that I call incorrectly? How can I use the writeFileAsync method? ![image](uploading ...)
Owner

Currently, writeFileAsync is only really relevant for NodeJS, as it uses fs.writeFile rather than fs.writeFileSync.

In the browser, if you want "asynchronous export", use a web worker. Check the worker demo https://docs.sheetjs.com/docs/demos/worker#creating-a-local-file and take a look at the live demo to see how to organize the export (the live demo uses a ReactJS component but the same works with "vanilla JS" or any framework)

Currently, `writeFileAsync` is only really relevant for NodeJS, as it uses `fs.writeFile` rather than `fs.writeFileSync`. In the browser, if you want "asynchronous export", use a web worker. Check the worker demo https://docs.sheetjs.com/docs/demos/worker#creating-a-local-file and take a look at the live demo to see how to organize the export (the live demo uses a ReactJS component but the same works with "vanilla JS" or any framework)
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#2895
No description provided.