print_string, print_int, etc. work fine when compiled with bsc, but they do not print anything when the resulting JS file was bundled with webpack. I tested bs-platform of versions 0.9.3 and 1.0.1, both of which caused the same problem.
To reproduce result:
print_endline " ";
Js.log "hello world"
webpack main_entry.js bundle.js
When built and run with npm run build && node main_entry.js, you get:
npm run build && node main_entry.js
When built and run with npm run build && webpack main_entry.js bundle.js && node bundle.js, you get:
npm run build && webpack main_entry.js bundle.js && node bundle.js
I looked into lib/js/caml_io.js, and I noticed that the value of process.stdout is undefined in caml_ml_output() in webpack bundle bundle.js, which results in printing nothing.
@nebuta it is very hard to simulate io in the browser environment, since what we only have is console.log which will always insert a new line, while print_int does not insert a new line.
Js.log seems to be more powerful, any particular reason that you would like print_* compared with Js.log?
Thank you. Actually, there is no particular reason I want to use print_* functions, and I will just use Js.log and string_of_* functions for console output. I just thought this might be the problem with code generation in general, but I think it is just fine if this is not such a code generation problem (the behavior changed when webpack was used, which seemed weird to me).
Maybe adding such a note of caution to the documentation would be great, since it is very common for a newcomer to test these stdout functions.
clarified in docs: 9ab9e2f#diff-18c2beafb3b63196491fa80bb019689bR42