cbuild
cbuild copied to clipboard
Building with xlsx npm module fails
I run into this yesterday:
> cbuild -d -v -m systemjs-hot-reloader -o dist/bundle.js -C config-npm.js
Bundling for development (NODE_ENV = undefined and --debug set)
Build error:
Error on fetch for fs.js at file:///Users/jta/tmp/hierarchicaltable-example-app/fs.js
Loading node_modules/xlsx/xlsx.js
Loading node_modules/makeMaps/dist/ui_components/import_wizard/FileUploadView.js
Loading node_modules/makeMaps/dist/ui_components/import_wizard/LayerImportWizard.js
Loading node_modules/makeMaps/dist/MakeMaps.js
Loading dist/index.js
Error: ENOENT: no such file or directory, open '/Users/jta/tmp/hierarchicaltable-example-app/fs.js'
at Error (native)
I believe the module https://github.com/SheetJS/js-xlsx is the culprit. It would seem cbuild doesn't see node's internal modules correctly and tries to find them in the project folders?
I can make a complete test case later if you wish, but wanted to report this already...
cbuild
could probably map that to an empty module or browserify's Node.js library implementations, but shipping a whole filesystem emulation for browser use goes a bit against cbuild
philosophy of reducing bloat. Is there a way to remove the fs
dependency or would an empty module work in its place?
It's a dependency of a dependency so removal is not possible. I believe it's related to file generation functionality (it makes an excel file inside the browser) and probably uses features from fs for this.
I can try the empty module trick. I'm not entirely sure if the dependency is actually relevant and what happens then. Also, there's a possibility of using bundled version of these dependencies. I can't figure out how those should be declared to cbuild.
Is this more SystemJS' feature than cbuild? I'd like to declare these modules so that they could be found when required, even if they produce bloat.