emscripten-core / emscripten-core/emscripten

MAIN_MODULE and emscripten_fetch

Open
#11,407 5 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Dear all,

I experience problems using the Fetch API together with WebAssembly modules.

Firstly, I copy/paste the exact sample code from the [Introduction section of the Fetch API](https://emscripten.org/docs/api_reference/fetch.html#introduction), and put it inside a file called `test.c`.

Secondly, I create a basic `index.html` as follows:

```


Test



```

Finally, I compile the WebAssembly binaries (version 1.39.17 of Emscripten), and serve them using Python as follows:

```
export FLAGS="-s MAIN_MODULE=1 -s EXPORT_ALL=1 -s FETCH=1 -s WASM=1"
~/Downloads/emsdk/upstream/emscripten/emcc ${FLAGS} -DNDEBUG -O2 -o test.o -c test.c
~/Downloads/emsdk/upstream/emscripten/emcc ${FLAGS} -DNDEBUG -O2 test.o -o test.js
python -m SimpleHTTPServer 8000
```

When I open `http://localhost:8000/`, I get the following errors in the console:
* `Maximum call stack size exceeded` on Chromium, and
* `InternalError: too much recursion,__emscripten_fetch_load_cached_data` on Firefox.

The problem disappears if I don't use modules (i.e. if I remove `-s MAIN_MODULE=1`). Would the Fetch API be incompatible with WebAssembly modules? Is there a way to solve this issue?

Thanks for your great work on Emscripten!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.