# Compiling to WASM for JS

**URL:** <https://forum.crystal-lang.org/t/compiling-to-wasm-for-js/5132>\
**Category:** Help & Support\
**Created:** [November 24, 2022, 6:28pm UTC](https://forum.crystal-lang.org/t/compiling-to-wasm-for-js/5132 "2022-11-24T18:28:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwoertink](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/jwoertink/32/50_2.png) [@jwoertink](https://forum.crystal-lang.org/u/jwoertink)\
**Post date:** [November 24, 2022, 6:28pm UTC](https://forum.crystal-lang.org/t/compiling-to-wasm-for-js/5132/1 "2022-11-24T18:28:41Z")

</div>

Following a few posts I was able to get Crystal to compile to WASM with wasi. From what I understand, WASI is just the basic WASM without any Javascript stuff added. It sounds like in order to get WASM actually in the web, it needs to target emscripten?

Has anyone had success doing this?

```bash
> crystal build sum.cr -o sum.wasm --target wasm32-emscripten

In /usr/share/crystal/src/string.cr:1:1

 1 | require "c/stdlib"
     ^
Error: can't find file 'c/stdlib'

```

I tried to changing the target, but get some missing libs. I know for the WASI stuff, I needed to build [GitHub - lbguilherme/wasm-libs](https://github.com/lbguilherme/wasm-libs/) and copy the wasi libs over. I assume I’m missing something for doing emscripten, but I’m not sure what.

I also have [wasmer](https://wasmer.io/) installed, but didn’t see any docs on converting the format over (if that’s even a thing)… My goal is to use [WebAssembly.instantiateStreaming() - WebAssembly | MDN](https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/instantiateStreaming) and access WASM functions from javascript.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [November 24, 2022, 8:32pm UTC](https://forum.crystal-lang.org/t/compiling-to-wasm-for-js/5132/2 "2022-11-24T20:32:18Z")

</div>

These shards should hell with what you’re looking for:

> **[GitHub - lbguilherme/crystal-js: Bindings to use Crystal compiled to...](https://github.com/lbguilherme/crystal-js)**
>
> Bindings to use Crystal compiled to WebAssembly in a JavaScript environment, such as Node.js, Deno or the Web. - GitHub - lbguilherme/crystal-js: Bindings to use Crystal compiled to WebAssembly in ...

> **[GitHub - lbguilherme/crystal-web: Crystal bindings to the Web APIs for...](https://github.com/lbguilherme/crystal-web)**
>
> Crystal bindings to the Web APIs for building front-end applications with WebAssembly - GitHub - lbguilherme/crystal-web: Crystal bindings to the Web APIs for building front-end applications with W...

---

<div class="post-metadata">

**Author:** ![orangeSi](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/orangesi/32/1569_2.png) [@orangeSi](https://forum.crystal-lang.org/u/orangeSi)\
**Post date:** [November 28, 2022, 1:19am UTC](https://forum.crystal-lang.org/t/compiling-to-wasm-for-js/5132/3 "2022-11-28T01:19:20Z")

</div>

@noaheverett had a tutorial about webassembly in Crystal at [WebAssembly Host Functions in Crystal by @noah | Glue](https://glue.im/noah/webassembly-host-functions-in-crystal)

---

<div class="post-metadata">

**Author:** ![jwoertink](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/jwoertink/32/50_2.png) [@jwoertink](https://forum.crystal-lang.org/u/jwoertink)\
**Post date:** [November 28, 2022, 5:27pm UTC](https://forum.crystal-lang.org/t/compiling-to-wasm-for-js/5132/4 "2022-11-28T17:27:03Z")

</div>

Yeah, I read those. They are really great posts! Though, they are meant for server-side WASM, and not client-side. Still totally recommended though. Thanks
