emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

runMetaWithFS always use XHR and fails in nodejs environment

Open jeffguorg opened this issue 1 year ago • 1 comments

Please include the following in your bug report:

Version of emscripten/emsdk: emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.64 (a1fe3902bf73a3802eae0357d273d0e37ea79898) clang version 19.0.0git (https:/github.com/llvm/llvm-project 4d8e42ea6a89c73f90941fd1b6e899912e31dd34) Target: wasm32-unknown-emscripten Thread model: posix InstalledDir: /home/[myname]/Workspace/github.com/emscripten-core/emsdk/upstream/bin

Failing command line in full: Full link command and output with -v appended:

I was compiling libreoffice to wasm and emscripten + libreoffice already did a great job. but when i used the generated output, i found that it works in browser but not in nodejs. it says XMLHttpRequest is not defined. i tracked down the whole build process and found that libreoffice is using --separate-metadata and it generated a function called runMetaWithFS

https://github.com/emscripten-core/emscripten/blob/54c570094fa5bf48151e4a79d78a50a2b3c612c2/tools/file_packager.py#L1113-L1118

i temporarily work around it by modify locally installed emscripten like this:

  1113   function runMetaWithFS() {
  1114     Module['addRunDependency']('%(metadata_file)s');
  1115     var REMOTE_METADATA_NAME = Module['locateFile'] ? Module['locateFile']('%(metadata_file)s', '') : '%(metadata_file)s';
  1116     if (                
  1117       typeof process === "object" &&
  1118       typeof process.versions === "object" &&
  1119       typeof process.versions.node === "string"
  1120     ) {                 
  1121       require("fs").readFile(REMOTE_METADATA_NAME, function (err, contents) {
  1122         if (err) {      
  1123           console.log(err)
  1124         } else {        
  1125           loadPackage(JSON.parse(contents.toString()))
  1126         }               
  1127       });               
  1128       return;           
  1129     }  

jeffguorg avatar Aug 06 '24 07:08 jeffguorg

Are you set in using --preload-file for some reason over --embed-file? That latter is much more effecient and I would only really recommend the former if you want to be able to separately update your data without updating the binary. (sorry if I've asked this already).

sbc100 avatar Aug 06 '24 18:08 sbc100