question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use this package on browser

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:24 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
charlliecommented, May 28, 2019

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

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

4reactions
RRGT19commented, Jun 3, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use npm modules in browser? is possible to use them ...
I'm new to npm module and node.js so it is really difficult to me. I have a js code whit many points and...
Read more >
I'm unable to install the Connective browser package
Possible cause, Solution. You're using an operating system that is not or no longer supported. Use an officially supported operating system.
Read more >
Troubleshooting - Unity - Manual
For example, if the Package Manager can't access the package registry server, it displays this message in the status bar: Network error message....
Read more >
@azure/msal-browser - npm
See here for more info on how to use this package from the Microsoft CDN. Usage. Migrating from Previous MSAL Versions.
Read more >
Troubleshooting | Cypress Documentation
If Cypress cannot find a browser but you know you have it installed, there are ways to ensure that Cypress can "see" it....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found