'wasm' build doesn't work with emscripten

Author: ChrisJeffersonCreated Sep 18, 2026Updated Sep 22, 2026
Labelswasm

AI Policy

  • I have read the AI Policy and this issue complies with it.

Problem

I was using tree-sitter in another project. It was working well, even when building to wasm, until I needed to switch to wasm32-unknown-emscripten, at which point I got all kinds of build failures about fprintf and fwrite.

I did at this point ask codex to help me figure out what was going on (because I wasn't even sure where the issue was), together we figured out them problem is emscripten provides a C standard library, and that conflicts with the small amount of C library which tree-sitter provides to help with wasm.

Once I knew what the problem was, I went looking myself into how tree-sitter added these functions and how to disable them. I have a PR to fix this but it's basically one line, we don't need 'configure_wasm_build' when using emscripten. The current 'target.starts_with("wasm32-unknown")' catches wasm32-unknown-emscripten . If we make sure it doesn't catch this case (for example just explictly matching wasm32-unknown-unknown), the build works and links fine (I've produced fully working web apps using this fix).

Steps to reproduce

This is a little hard to test. Make a rust project that links:

a) tree-sitter and b) another piece of C++ code which uses the standard library, and the result doesn't currently link.

cargo build --target wasm32-unknown-emscripten

Produce

wasm-ld: error: duplicate symbol: fwrite
          >>> defined in /Volumes/Acasis/caches/cargo-build/wasm32-unknown-emscripten/debug/deps/libtree_sitter-b7fc3791436c21ab.rlib(98490c8781b409d2-lib.o)
          >>> defined in /opt/homebrew/Cellar/emscripten/6.0.9/libexec/cache/sysroot/lib/wasm32-emscripten/libc-debug.a(fwrite.o)

I can try to make a minimal example if you like

Expected behavior

Can build with emscripten

Tree-sitter version (tree-sitter --version)

tree-sitter 0.27 (also tried latest dev branch)

Operating system/version

MacOS 26.7