securedeveloper / react-data-export

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

Error by importing the project #85

Open ogodon opened 5 years ago

ogodon commented 5 years ago

Hello,

I'm trying to use this exciting library. After installing the react-data-export package in my existing react application I get an error when I import the package by using import ReactExport from 'react-data-export';

I have the following error.

../framework/~/tempa-xlsx/xlsx.js
Module not found: Error: Cannot resolve module 'fs' in /home/ogodon/projects/framework/node_modules/tempa-xlsx
resolve module fs in /home/ogodon/projects/framework/node_modules/tempa-xlsx
  looking for modules in /home/ogodon/projects/company/node_modules
    /home/ogodon/projects/company/node_modules/fs doesn't exist (module as directory)
    resolve 'file' fs in /home/ogodon/projects/company/node_modules
      resolve file

Module fs cannot be found. So my question would be : is this package only meant to be used on a server context ?

Thank you for your time.

securedeveloper commented 5 years ago

Hi @ogodon, you need to explicitly define fs in configuration file, for example, in case of webpack, add following lines to your webpack.config.js file,

.....
node: {fs: 'empty'},
externals: [
    {'./cptable': 'var cptable'},
    {'./jszip': 'jszip'}
 ]

Hope that will help.

xariaSg commented 5 years ago

I have the same error. I created a react app using create-react-app. The didn npm run eject. Added the above configs to webpack.config.js. And still get the error.

Failed to compile.

./node_modules/tempa-xlsx/ods.js
Module not found: Can't resolve 'xlsx' in 'C:\Projects\my-app\node_modules\tempa-xlsx'
aleknak commented 5 years ago

@xariaSg npm install xlsx --save solved it for me.

xaviergeorge commented 2 years ago

@xariaSg npm install xlsx --save solved it for me.

The whole purpose of react-data-export is "(❗️❗️❗️The purpose of having a new library is that open source libraries either does not support styling and rest functionality in excel or they are too heavy to consider)". xlsx module is a heavy one. It has a size of 10MB. So this shouldn't be a proper solution.

grazielleanna commented 2 years ago

Hi @ogodon, you need to explicitly define fs in configuration file, for example, in case of webpack, add following lines to your webpack.config.js file,

.....
node: {fs: 'empty'},
externals: [
    {'./cptable': 'var cptable'},
    {'./jszip': 'jszip'}
 ]

Hope that will help.

Hi!

I created my project with create-react-app and didn't find where to add this setting to solve the problem.

How i can do this?

arindam-grene commented 2 years ago

Hi @ogodon, you need to explicitly define fs in configuration file, for example, in case of webpack, add following lines to your webpack.config.js file,

.....
node: {fs: 'empty'},
externals: [
    {'./cptable': 'var cptable'},
    {'./jszip': 'jszip'}
 ]

Hope that will help.

Hi!

I created my project with create-react-app and didn't find where to add this setting to solve the problem.

How i can do this?

You can check out this: https://github.com/securedeveloper/react-data-export/issues/168#issuecomment-1013556528