# Has any attempt been made to transpile Julia to JS?

**URL:** <https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386>\
**Category:** General Usage\
**Created:** [September 28, 2020, 2:06am UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386 "2020-09-28T02:06:42Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [September 28, 2020, 2:06am UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/1 "2020-09-28T02:06:42Z")

</div>

Are there plans to do so? I think it may open up new horizons: web UIs, …

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 28, 2020, 2:19am UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/2 "2020-09-28T02:19:12Z")

</div>

[https://github.com/Keno/julia-wasm](https://github.com/Keno/julia-wasm)

and I think (literally) transpile to JS is in general impossible.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [September 28, 2020, 3:45am UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/3 "2020-09-28T03:45:16Z")

</div>

I am asking because I just saw the VPython’s successful branching out into collaboration with JS (and the WebGL enabled by this marriage of convenience).

If the transpilation of Julia to JS was really impossible, that would be a pity.

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [September 28, 2020, 6:41am UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/4 "2020-09-28T06:41:44Z")

</div>

Another option would be to compile a web engine together with julia and an interface to manipulate the document object model directly from julia. That would make it possible to build nice user interfaces based on web technologies without going via javascript.

(This wouldn’t be a web browser. It would only run julia code supplied by the user, so one would not have to worry about all the security implications of running potentially malicious code.)

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [September 28, 2020, 7:32am UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/5 "2020-09-28T07:32:19Z")

</div>

Julia transpile (btw: why trans? it’s called compile) to anything would include a method to compile to static code and that would limit/exclude a long list of optimizations.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [September 28, 2020, 10:57am UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/6 "2020-09-28T10:57:11Z")

</div>

> [@lobingera](#):
>
> btw: why trans? it’s called compile

I believe Petr was thinking about a [source-to-source _trans_-lator](https://en.wikipedia.org/wiki/Source-to-source_compiler)

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [September 28, 2020, 2:48pm UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/7 "2020-09-28T14:48:03Z")

</div>

[JavaScript Transpilers: What They Are And Why We Need Them | DigitalOcean](https://scotch.io/tutorials/javascript-transpilers-what-they-are-why-we-need-them#:~:text=Transpilers%2C%20or%20source%2Dto%2D,are%20said%20to%20target%20JavaScript).

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [September 28, 2020, 10:39pm UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/8 "2020-09-28T22:39:52Z")

</div>

What would that give you that a wasm compiler target wouldn’t?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [September 28, 2020, 10:43pm UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/9 "2020-09-28T22:43:37Z")

</div>

Access to JS libraries?

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [September 29, 2020, 3:28pm UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/10 "2020-09-29T15:28:34Z")

</div>

You can call JS from wasm, not a problem. The issue is just the maturity of the platform.

---

<div class="post-metadata">

**Author:** ![Orbots](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orbots/32/3392_2.png) [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Post date:** [October 2, 2020, 2:12am UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/11 "2020-10-02T02:12:02Z")

</div>

> [@Keno](#):
>
> The issue is just the maturity of the platform.

Is there something in wasm preventing it working as a full featured julia compilation target? Curious what the state of julia-wasm is.

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [October 2, 2020, 4:15am UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/12 "2020-10-02T04:15:39Z")

</div>

It needs some features in wasm that are implemented, but experimental. Last I tried (about 6 months ago), the browsers liked to crash on our wasm output. I filed relevant bugs, so my hope is that when I have the time to look again, it’ll just work.

---

<div class="post-metadata">

**Author:** ![apo383](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/apo383/32/11272_2.png) [@apo383](https://discourse.julialang.org/u/apo383)\
**Post date:** [October 2, 2020, 4:25am UTC](https://discourse.julialang.org/t/has-any-attempt-been-made-to-transpile-julia-to-js/47386/13 "2020-10-02T04:25:51Z")

</div>

> btw: why trans? it’s called compile

I think because not exactly translation nor compilation. Source-to-source translation implies that a human might look at the result, or interact with it in some way before compiling it. They want source. Otherwise they should just compile directly to a linkable library (e.g. \*.so object code). And traditionally, compilation refers to converting source into (non-readable) object code.

Here, translation is done to JS but with no interest in human reading. It’s meant to be executed (by a browser), and yet it’s neither object nor machine code. But it’s roughly equivalent to a platform-independent object code, made fast by good interpreters/JITs. See [Gary Bernhardt’s talk](https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript) about this very topic.

Nowadays, the lines are quite blurry. Machine code isn’t what it used to be, because underneath it is not “bare metal” but more layers of interpretation, e.g. micro-code or micro-operations. The CPU is interpreting instructions and doing all sorts of re-ordering, branch prediction, pipelining, cache management, etc. So maybe we should do away with the word compilation, since it’s turtles many levels down. (There _is_ bare metal down there, somewhere.) But almost everything these days is interpretation or a translation (transpilation?) to another intermediate representation.
