Solvedexceljs Can't use this package on browser

I'm trying to use exceljs on browser to read some XLSX files.
But, when I tried to import using

import Excel from 'exceljs';

I received an error on build because can't resolve fs module:

ERROR in ./node_modules/exceljs/dist/es5/csv/csv.js
Module not found: Error: Can't resolve 'fs' in '/my-project/node_modules/exceljs/dist/es5/csv'
ERROR in ./node_modules/exceljs/dist/es5/utils/utils.js
Module not found: Error: Can't resolve 'fs' in '/my-project/node_modules/exceljs/dist/es5/utils'
ERROR in ./node_modules/exceljs/dist/es5/xlsx/xlsx.js
Module not found: Error: Can't resolve 'fs' in '/my-project/node_modules/exceljs/dist/es5/xlsx'
...

Searching about how is the correct way to import on browser, I found this example, and following it I tried importing using

const ExcelJS = require('exceljs/dist/es5/exceljs.browser');

But this command also didn't work, returning the same errors.

Also I found a related open issue about this problem.

Then.... is there a way to import exceljs on browser?

23 Answers

✔️Accepted Answer

I solved this by adding:
declare const ExcelJS: any;

and in angular.json:
"scripts": [ ... "node_modules/exceljs/dist/exceljs.min.js" ]

Other Answers:

Change your import to ExcelJS, like this:

import * as ExcelJS from 'exceljs/dist/exceljs.min.js';

Hi @abmj1979,
Thanks, it's working now. What I didn't understand is why the line declare const ExcelJS: any; should be there.

Also, why we need to add exceljs.min.js in angular.json if we are already using it as an import in our service.

Related Issues:

69
exceljs Add a rows before the columns headers
By that example do this @rihabbs That's about it Hi how can i add a rows before the column header? ...
20
exceljs "Zone.js has detected that ZoneAwarePromise (window|global).Promise has been overwritten
fixed mine by importing it before 'core-js' and 'zone.js' in the pollyfills.ts file pollyfills.ts fi...
15
exceljs Cannot resolve module 'fs' on client side
@Ahmad19860 So .writeFile relies on node.js libraries in order to function So we can't actually use ...
15
exceljs Can't use this package on browser
I solved this by adding: declare const ExcelJS: any; and in angular.json: scripts: [ .. node_modules...
246
sheetjs How to simply export a Worksheet to xlsx?
There are two issues: each object is mapped to a row so if you want a row with name John and city Se...
112
Laravel Excel Error Opening file with Excel. Possible data corrupted or bad file extension.
Hi everyone I spend my day to understand this unworkable download function PHPSpreadSheet seems to u...
79
sheetjs Doesn't work with browserify or webpack.
I was able to get it building by adding the following to my webpack config: EDIT: please raise a new...
60
Laravel Excel [BUG] import date format issue
I started working on a PR but quickly realized that it was going to be complicated to implement ...
45
sheetjs Corrupt XLSX file after downloading
Ok Sorry for the monologue but I solved it: In the frontend when making the GET Request ...
44
sheetjs Change header´s title when using json_to_sheet
There's no json_to_xlsx function you probably mean json_to_sheet That being said the easiest way is ...
44
Laravel Excel How to: save csv/xls files using ajax only
I needed to return an xlsx from ajax so I tweaked again a little and this is what I end up with: PHP...
32
spout Get validation error message after opening created .xlsx file
This is not a library issue Use exit; immediately after $writer->close(); as with downloading files....
28
Laravel Excel Start row (2) is beyond highest row (1)
i have same error ! but after remove sheet 2 3 solved !! for this situation you need define sheet in...
27
sheetjs how to set the automatic width?
@cjlhll Please see my solution get maximum width from the json data set column width ...
23
Laravel Excel How to insert clickable hyperlink in excel?
when use v3.* u can like this to set hyper link Helpful solution but you can do it more understandab...
20
sheetjs merge cells from Array of Arrays
You need to build up the worksheet first then add the merges to the worksheet Hi ...
17
Laravel Excel [QUESTION] XLS export not working
@edanao try cleanin the buffer before calling download function There must be some space symbol in t...
15
sheetjs format Date question
On the read side you also need to pass cellText:false: In the conversion you shouldn't set raw: raw:...
14
sheetjs Date conversion loses 1 day
My date in excel is 2019-03-04 and finally i got 2019-03-03T15:59:17.000Z when XLSX.utils.sheet_to_j...
13
Laravel Excel [BUG] Error import: object beginTransaction
Maybe you guys are having the same issue I did at #2384 Maybe my solution would work for you try a: ...
11
sheetjs Get the header column from excel
@kalai7890 If you just want to pull the header row the easiest way is to just walk the cells in the ...
5
node csvtojson fs.exists is not a function
It seems you are trying to use the lib in Browser and fs module only exists in nodejs For browser ...
3
visidata AttributeError: '_curses.curses window' object has no attribute 'get_wch'
@qrkourier I just followed pyenv/pyenv#240 (comment): with a few changes Now it works. ...
3831
axios Axios catch error returns javascript error not server response
I have exactly the same environment Try this: Modify from console.log(error) to console.log(error.re...
731
scrapy ' error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 '
@euler16 for scrapy with Python 3 you'll need with Python 2 you'll need I wanted to install scrapy i...
684
laradock Mysql. The server requested authentication method unknown to the client [caching_sha2_password]
alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it....
517
react navigation screenIsActive prop / componentDidFocus event for TabNavigator items
It probably makes sense to add lifecycle hooks to screens In one of my Tabs i need to load Data from...
474
meteor [1.4.2.1] Error: ENFILE: file table overflow
I was getting the same after an upgrade to macOS Sierra Turns out macOS have a harsh limit on number...
423
ipython Last jedi release (0.18.0) is incompatible with ipython (7.19 and 7.18 tested); reason - column arg was deprecated, and now removed
As a temporary fix for anyone just trying to get things working again: It would be really nice if yo...
397
material ui Module not found: Can't resolve 'material-ui-icons/Menu' Martial Next
For anyone else experiencing this issue: npm install @material-ui/icons https://www.npmjs.com/packag...
395
laravel dompdf (1/1) ErrorException Non-static method Barryvdh\DomPDF\PDF::loadView() should not be called statically
This happens because you are namespacing the wrong PDF class You are namespacing Barryvdh\DomPDF\PDF...
378
webpacker localIdentName option moved in css-loader configuration
I faced same issue after upading css-loader but I solved it If you check css-loader readme ...
364
react navigation Send data back from child screen?
@itswaze You can do something along these lines to pass back from the child screen ...
358
react navigation How to goBack from nested StackNavigator?
@dhruvparmar372 According to the NOTE in the doc a navigator's navigation prop may not have the help...
352
axios POST request works in Browser but not on Node
This might be considered a duplicate of #789 I was able to use the form-data package with Axios in n...
317
react navigation Best pattern for a 'Save' button in the header
Try setting your component instance's handleSave function as a navigation state parameter after the ...
310
DefinitelyTyped [@types/react] RefObject.current should no longer be readonly
It's not It'a intentionally left readonly to ensure correct usage even if it's not frozen ...
306
react native navigation [V3][Android] FATAL EXCEPTION: create_react_context
OK after a good night of sleep I've found why I was having this issue In the MainApplication.java I ...
303
ts node Custom typings not working with ts-node 8.0.2
When using with ts-node you have to add --files flag After updating to ts-node version 8.0.2 the cus...
294
ohmyzsh compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew
Per #9602 (comment) brew cleanup fixed it for me I am using Apple M1 When I added this line: export ...
292
laradock SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
+1 I'm having the same problem here. Info: Docker version ($ docker --version): Docker version 17.12...
289
vagrant vagrant box update - Fails with 404 Not Found error
A workarround to add in your Vagrantfile: Vagrant version Host operating system Ubuntu 16.04.3 LTS G...
263
vagrant vagrant --help displays a rubygems error
To fix this error: Vagrant version Host operating system Expected behavior vagrant and vagrant --hel...
262
date fns Can't resolve 'date-fns/_lib/format/longFormatters'
You probably forgot to install date-fns or Code: import DateFnsUtils from '@date-io/date-fns'; ...
259
virtualenv Error creating virtualenv with python3.6
The original poster's problem is due to not having the 'python3.6-venv' package installed ...
252
provider A Product was used after being disposed. flutter: Once you have called dispose() on a Product, it can no longer be used.
Oh I see what you're doing Don't: DO: i have a ChangeNotifireProvider that such that i do pushReplac...
248
react navigation Reset to nested route, "There is no route defined for..."
A quick workaround (not heavily tested): set the key property to null on your action. ...
238
axios Adding headers to axios.post method
Edit: I had to add Authorization to allowed headers in my CORS filter @jffernandez I'm having the sa...
231
axios Adding Retry Parameter
@mericsson I am too in need of exponential backoff when retrying I've put together the following whi...