Reputation: 1117
I am building my webpage using react. I want to download my reducer's store data into a xlxs file. For that I am using exceljs
package.
I have install the exceljs
using npm i exceljs
.
But when I tried to import exceljs
to my componenet I am getting TypeError: Cannot read property 'prototype' of undefined
on the screen.
I am importing using command import Excel from "exceljs";
.
Please have a look to screenshoot for better error view that I am getting on my screen.
my package.json is:
{
"name": "xxxxxxx_xxxxx",
"version": "0.1.0",
"private": true,
"dependencies": {
"exceljs": "^1.6.0",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-intl": "^2.4.0",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.4",
"redux": "^4.0.0",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build:langs": "NODE_ENV='production' ./node_modules/.bin/babel src --out-dir lib",
"build:locale": "NODE_ENV='production' babel-node scripts/translator.js",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-react-intl": "^2.4.0"
}
}
Upvotes: 4
Views: 11011
Reputation: 1
I managed to fix the issue by importing like this:
const ExcelJS = await import('exceljs');
Upvotes: 0
Reputation: 31
I got it working by using:
import * as Excel from "exceljs/dist/exceljs.min.js";
rather than
import Excel from "exceljs/dist/es5/exceljs.browser";
Upvotes: 3
Reputation: 1135
It seems like ExcelJS's exports are a bit weird for browser. I got it to work by doing:
import Excel from "exceljs/dist/es5/exceljs.browser";
Then you can use Excel
however you like. I.e:
console.log('excel', Excel); // Check that it exists
var workBook = new Excel.Workbook(); // Make a new Workbook
Upvotes: 2