securedeveloper / react-data-export

Export dataset in react.
https://securedeveloper.github.io/react-data-export/
MIT License
179 stars 191 forks source link

Runtime error finding jszip #158

Closed mgralle closed 3 years ago

mgralle commented 3 years ago

I am using react-data-export 0.6.0 in a setup with browserify (16.5.2) in gulp (4.0.2). When running my project in the browser, the line

import ReactDataExport from 'react-data-export';

in one of my ES6 files triggers the error message:

_prelude.js:1 Uncaught Error: Cannot find module 'jszip' at o (_prelude.js:1) at _prelude.js:1 at make_xlsx (xlsx.js:1344) at Object. (xlsx.js:12576) at Object. (xlsx.js:12578) at Object./.../node_modules/tempa-xlsx/xlsx.js../dist/cpexcel (xlsx.js:12578) at o (_prelude.js:1) at _prelude.js:1 at Object./.../node_modules/react-data-export/dist/ExcelPlugin/components/ExcelFile.js.../elements/ExcelSheet (ExcelFile.js:19) at o (_prelude.js:1)

This message appears even if I don't actually use the imported ReactDataExport.

My package.json contains the lines

"dependencies": {...
  "file-saver": "^1.3.3",
    "jszip": "^3.5.0",
    "react-data-export": "^0.6.0",
    "tempa-xlsx": "^0.8.20",
    "xlsx": "^0.15.6",
    "xlsx-style": "^0.8.13"
}

I have seen your explanation how to set up webpack.config.js, but I don't know how to tell gulp to handle jszip as an external. I have tried many iterations of adding and removing dependencies and trying out different node and npm versions. Currently I am using node 16.0.0 and npm 7.10.0. Can you give some suggestion?

Thanks a lot.

mgralle commented 3 years ago

So I have found I needed to add the following entry to the browserify option in my gulpfile:

require: [
      'jszip'
    ]