fix(wasm): resolve playground "env" module error#39
Merged
Conversation
The wasm-bindgen generated JS contains `import * from "env"` statements for 12 C stdlib functions that tree-sitter needs (malloc, free, fprintf, etc.). Browsers cannot resolve bare module specifiers, causing the playground to fail on load. Fix: add an import map to index.html that maps "env" to a local env.js shim providing no-op stubs. The Rust allocator handles actual memory management via wasm-bindgen; these C stubs exist only to satisfy WebAssembly.instantiate. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
JuanMarchetto
approved these changes
Feb 26, 2026
jeanclawdbotdamn
added a commit
that referenced
this pull request
Feb 26, 2026
tree-sitter's C code references malloc/free/fprintf/etc. which become unresolved "env" imports in the WASM binary. Browsers cannot resolve the bare "env" module specifier, causing the playground to fail. Previous fix (PR #39) added JS shims via import map, but malloc returning NULL caused tree-sitter to call abort() at runtime. This fix provides real #[no_mangle] implementations in Rust: - malloc/calloc/realloc/free: route to Rust's global allocator with an 8-byte size header so free/realloc can reconstruct the Layout - fprintf/snprintf/vsnprintf/fwrite/fputc/fclose: no-op stubs (tree-sitter declares but never calls these in the validation path) - clock: returns 0 - abort: triggers wasm32::unreachable trap The linker resolves these at build time, eliminating all "env" imports from the generated JS. Removes the now-unnecessary env.js shim and import map. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Uncaught TypeError: Failed to resolve module specifier "env"import * from "env"for 12 C stdlib functions tree-sitter needs (malloc,free,calloc,realloc,abort,fprintf,snprintf,vsnprintf,fclose,clock,fwrite,fputc). Browsers cannot resolve bare module specifiers.index.htmlmapping"env"→./pkg/env.js, and provide a shim with no-op stubs for all 12 functionsWebAssembly.instantiateFiles changed
playground/env.jsplayground/index.html<script type="importmap">.github/workflows/pages.ymlenv.jsto_site/pkg/Test plan
🤖 Generated with Claude Code