While there is a correct answer already given at:
SPFx Unable to use 'fs' module
its missing the part that in webpack config it can be outflagged
like this:
node: { fs: 'empty' },
Module not found: Error: Can't resolve 'fs'
But I cannot find such a config file in a SPFx react web-part structure or does it has something to do with gulp configuration?
EDIT
I am trying to write state data of an react application into an excel-sheet. Therefore I used already react-csv
which seems to be like the name says simply comma separated so its not really readable with big data, react-export-excel
and considered using .xlsx
.
While using react-export-excel
I recognized that it is already using the .xlsx
package as an dependency. Those packages try to use fs
for writing data into an excel-sheet. I know that it should be handled in the back-end but SharePoint online won't let me do this.
Here is the error code:
[06:49:00] Error - [webpack] 'dist': ./node_modules/react-export-excel/node_modules/xlsx/xlsx.js Module not found: Error: Can't resolve 'fs' in 'C:\Projects.........\node_modules\react-export-excel\node_modules\xlsx'
looking for modules in C:\Projects.........\node_modules\react-export-excel\node_modules using description file: C:\Projects.........\node_modules\react-export-excel\package.json (relative path: ./node_modules) Field 'browser' doesn't contain a valid alias configuration
I hope I mentioned everything that is necessary.
EDIT II
It seems no one looked up the GitHub link because everyone is telling me that fs on clientside isn't working. While this is (OBVIOUSLY) true not all packages HAVE TO use 'fs' wether it is implemented or not. Excel reports are just MORE COMMON to be handled in backend AND THATS WHY most packages use 'fs' as an dependandy. THIS IS NOT necessary because the browser offers natives APIs to do similar but more simple things. So there has to be a way in SPFx like in normal React projects to tell webpack or gulp "DONT USE fs as an dependancy" with something like:
node: { fs: 'empty' },
and it will use the BROWSER API instead.
Answer was given by michaelcuneo: "It's irrelevant and your project will run perfectly fine without it. fs is for an underlying feature of exceljs and many other nodeJS modules that don't work inside a React.JS App. If you need to make the error go away because you're sick of looking at it... Go to webpack.base.babel.js inside /internals/webpack ... And add somewhere close to the bottom... mines directly above devtool: options.devtool ... node: { fs: 'empty' }, This will cause the webpack to ignore fs dependencies."
This should be doable in a SPFx project too!!!
I hope people will understand me better now.
node: { fs: 'empty' }
? Is there any error in your webpart when you rungulp serve
? If Yes, can you please add an error you are getting to your question? There might be different solution to your error.