print_string, etc. print nothing when bundled with webpack #748

nebuta opened this Issue Sep 10, 2016 · 3 comments


None yet

2 participants

nebuta commented Sep 10, 2016 edited

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_int 1;
print_char ':';
print_endline " ";
Js.log "hello world"
  • Run webpack main_entry.js bundle.js (without webpack.config.js)

When built and run with npm run build && node main_entry.js, you get:

hello world

When built and run with npm run build && webpack main_entry.js bundle.js && node bundle.js, you get:

hello world

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?

@bobzhang bobzhang added the RUNTIME:IO label Sep 10, 2016
nebuta commented Sep 10, 2016 edited

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.

@bobzhang bobzhang closed this Sep 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment