emscripten-core / emscripten-core/emscripten
runMetaWithFS always use XHR and fails in nodejs environment
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
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 ](https://github.com/LibreOffice/core/blob/dd47e4b30cb7dab30588d6c79c651f218165e3c5/static/CustomTarget_emscripten_fs_image.mk#L1520-L1524) 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 }
```
Contributor guide
Assessment
This issue has not been assessed yet.