# Swipl-bundle.js not working

**URL:** <https://swi-prolog.discourse.group/t/swipl-bundle-js-not-working/8863>\
**Category:** Help!\
**Tags:** bug, how-to, wasm\
**Created:** [March 8, 2025, 6:41pm UTC](https://swi-prolog.discourse.group/t/swipl-bundle-js-not-working/8863 "2025-03-08T18:41:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrii](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@andrii](https://swi-prolog.discourse.group/u/andrii)\
**Post date:** [March 8, 2025, 6:41pm UTC](https://swi-prolog.discourse.group/t/swipl-bundle-js-not-working/8863/1 "2025-03-08T18:41:40Z")

</div>

I compiled SWI-Prolog version 9.2.9 for WASM (cloned from git, emcc 4.0.4) and it seems to work fine with Node.js 18.9.0.

I want to be able to compile .qlf files of my projects to turn them into web apps. For that, I wanted to have one swipl locally to generate them, and then use the same version to interpret .qlf’s in a browser.

However, my compiled swipl-bundle.js does not seem to work in the browser. Namely,

```JS
swipl = await SWIPL()

```

gives `swipl` without `prolog` or `consult()`! I tried the same with swipl-bundle.js from the npm package and from the swi-prolog website, and it worked.

Any suggestions what could have happened?

NB: I invoked CMake as

```bash
emcmake cmake -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_FIND_ROOT_PATH=~/src/emsdk/wasm-root/ \
      -DINSTALL_DOCUMENTATION=OFF \
      -DUSE_GMP=OFF \
      -G Ninja ..

```

Maybe I should try the “official” way as in the manual, with pointing the toolchain path. I will also try to build a Debug version.

UPDATE: So, I compiled with -DCMAKE\_BUILD\_TYPE=Debug and I have now the following errors in the JS console:

> Aborted(Attempt to set `Module.onRuntimeInitialized` after it has already been processed. This can happen, for example, when code is injected via ‘–post-js’ rather than ‘–pre-js’)

> Unhandled Promise Rejection: RuntimeError: Aborted(Attempt to set `Module.onRuntimeInitialized` after it has already been processed. This can happen, for example, when code is injected via ‘–post-js’ rather than ‘–pre-js’)

This time I run CMake almost as described in the manual, calling

```bash
cmake -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \
      -DCMAKE_BUILD_TYPE=Debug \
      -DCMAKE_FIND_ROOT_PATH=$WASM_ROOT \
      -DINSTALL_DOCUMENTATION=OFF \
      -DUSE_GMP=OFF \
      -G Ninja ..

```

_directly_ from shell (after calling emsdk\_env.sh of course). The main difference with the manual is that it is suggested to put such a command into a script and run it with `bash`. Also, I disabled GMP.

I also noticed that for both times I compiled the WASM swipl, I got a warning:

> emcc: warning: `main` is defined in the input files, but `_main` is not in `EXPORTED_FUNCTIONS`. Add it to this list if you want `main` to run. [-Wunused-main]

when swipl-bundle.js and swipl-bundle-nodata.js were built.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [March 9, 2025, 9:13am UTC](https://swi-prolog.discourse.group/t/swipl-bundle-js-not-working/8863/2 "2025-03-09T09:13:27Z")

</div>

Try the development versions. 9.2.x notably does not contain the patches that are required for Emscripten 4. There should be no need to rebuild the WASM. The latest development version is compatible with the WASM release.

---

<div class="post-metadata">

**Author:** ![andrii](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@andrii](https://swi-prolog.discourse.group/u/andrii)\
**Post date:** [March 9, 2025, 11:24am UTC](https://swi-prolog.discourse.group/t/swipl-bundle-js-not-working/8863/3 "2025-03-09T11:24:40Z")

</div>

Thanks for a suggestion! Probably I should have mentioned this issue myself, as the compatibility with Emscripten 4 was already discussed…

However, I still can’t get swipl-bundle.js to work! Now I can see the following output in the JS console:

> [Error] ERROR: /swipl/library/wasm.pl:59:[Error] ERROR: source\_sink `library(uri)’ does not exist  
> [Error] Warning: /swipl/library/wasm.pl:59:  
> [Error] Warning: Goal (directive) failed: wasm:use\_module(library(uri),[uri\_is\_global/1,uri\_normalized/3,uri\_normalized/2])  
> [Log] wasm:file\_url/2: Unknown procedure: wasm:uri\_is\_global/1 (swipl-bundle-devel.js, line 8)

when creating the SWIPL object.

Althoug the object gets created somehow, and even contains `prolog` this time, running

```JS
swipl.prolog.query("memberchk(X, [sdsd,ghh])").once().X

```

yields

> [Log] wasm:wasm\_call\_string/3: Unknown procedure: wasm:exclude/3 (swipl-bundle-devel.js, line 8)

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [March 9, 2025, 2:46pm UTC](https://swi-prolog.discourse.group/t/swipl-bundle-js-not-working/8863/4 "2025-03-09T14:46:25Z")

</div>

Looks like (most of) the libraries are not included. Did you install from GIT? If so, did you clone the submodules?

---

<div class="post-metadata">

**Author:** ![andrii](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@andrii](https://swi-prolog.discourse.group/u/andrii)\
**Post date:** [March 9, 2025, 7:11pm UTC](https://swi-prolog.discourse.group/t/swipl-bundle-js-not-working/8863/5 "2025-03-09T19:11:45Z")

</div>

Indeed, I did not clone the submodules.

After executing

```bash
git submodule update --init

```

in the swipl-devel repository, it compiled and working like a charm.

I was also able to compile my .qlf and consult it in browser. Awesome!

Thank you so much!
