Uncaught TypeError: XLSX.read is not a function with dojo AMD #1937

Closed
opened 2020-05-08 04:03:50 +00:00 by adeebgithub · 4 comments
adeebgithub commented 2020-05-08 04:03:50 +00:00 (Migrated from github.com)

Hi
When I use xlsx.js along with dojo (js.arcgis.com/3.14compact/) and AMD i am getting below error
Uncaught TypeError: XLSX.read is not a function
at ProcessExcel (ADBInitExcel.js:52)
at FileReader.reader.onload (ADBInitExcel.js:26)

The html file and the script file is attached below
InitialPage.zip

Hi When I use xlsx.js along with dojo (js.arcgis.com/3.14compact/) and AMD i am getting below error Uncaught TypeError: XLSX.read is not a function at ProcessExcel (ADBInitExcel.js:52) at FileReader.reader.onload (ADBInitExcel.js:26) The html file and the script file is attached below [InitialPage.zip](https://github.com/SheetJS/sheetjs/files/4596929/InitialPage.zip)
SheetJSDev commented 2020-05-08 04:46:37 +00:00 (Migrated from github.com)

The fix is fairly straightforward and we'll accept a PR: the define call in https://github.com/SheetJS/sheetjs/blob/master/bits/99_footer.js#L6 should be

else if(typeof define === 'function' && define.amd) define(function() { if(!XLSX.version) make_xlsx_lib(XLSX); return XLSX; });
The fix is fairly straightforward and we'll accept a PR: the define call in https://github.com/SheetJS/sheetjs/blob/master/bits/99_footer.js#L6 should be ```js else if(typeof define === 'function' && define.amd) define(function() { if(!XLSX.version) make_xlsx_lib(XLSX); return XLSX; }); ```
adeebgithub commented 2020-05-09 21:27:23 +00:00 (Migrated from github.com)

Hi SheetJSDev

It worked. Thanks for the immediate support

Hi SheetJSDev It worked. Thanks for the immediate support
diaconori commented 2022-08-30 18:04:46 +00:00 (Migrated from github.com)

This doesn't work. I've downloaded the file and referenced it in my project. Dojo doesn't allow this to be ran through its AMD system.

This doesn't work. I've downloaded the file and referenced it in my project. Dojo doesn't allow this to be ran through its AMD system.
SheetJSDev commented 2022-08-30 19:31:55 +00:00 (Migrated from github.com)

tl;dr When async is enabled, Dojo will only understand the name xlsx. You have to adjust the package settings in dojoConfig to tell it to use the script.

https://docs.sheetjs.com/docs/getting-started/installation/amd#dojo-toolkit installation for sync and async loaders

https://docs.sheetjs.com/docs/demos/legacy#dojo-toolkit discussion

https://docs.sheetjs.com/dojo/read.html fetches data with dojo/request/xhr and parses with XLSX.read

https://docs.sheetjs.com/dojo/read.html fetches JSON data and writes a workbook with XLSX.writeFile

tl;dr When `async` is enabled, Dojo will only understand the name `xlsx`. You have to adjust the package settings in `dojoConfig` to tell it to use the script. https://docs.sheetjs.com/docs/getting-started/installation/amd#dojo-toolkit installation for sync and async loaders https://docs.sheetjs.com/docs/demos/legacy#dojo-toolkit discussion https://docs.sheetjs.com/dojo/read.html fetches data with `dojo/request/xhr` and parses with `XLSX.read` https://docs.sheetjs.com/dojo/read.html fetches JSON data and writes a workbook with `XLSX.writeFile`
Sign in to join this conversation.
No Milestone
No Assignees
1 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#1937
No description provided.