I have set up a js_of_ocaml project with dune and webpack. When I build it, I see a pair of JS files in the _build directory:
app.bc.js and app.bc.runtime.js. What is the runtime file, and what should I do with it? The app seems to work fine without it.
In addition, when I set target: "web"
in webpack config, I get the following errors:
Module not found: Error: Can’t resolve ‘child_process’ in …
Module not found: Error: Can’t resolve ‘fs’ in …
I get these errors even if I include the runtime file in the webpack bundle. If I set target: "node"
, the project builds without errors. I’m running the app in the browser, what should I target?
4 Likes
This still seems to be an issue. I created a minimal example that I would expect to work: GitHub - joelburget/jsoo-example. Any advice what’s going wrong here?
I’m using esbuild to build my files and you can say that some modules are external:
esbuild jsLib/index.js --outfile=out.js --bundle --platform=browser --minify --external:fs --external:tty --external:child_process"
I think some other build tools support this as well
With webpack, these errors can be fixed by including this section in webpack.config.js
:
node: {
fs: 'empty',
child_process: 'empty'
}
A complete working webpack.config.js
example here.
Thanks to both of you, that was exactly what I needed. I pushed a new branch (GitHub - joelburget/jsoo-example at webpack-5-resolution) demonstrating the fix.