Skip to content

compile NodeJS to wasm #3774

Closed as not planned
Closed as not planned

Description

@jimmywarting

Details

i have seen stackblitz.com compiling NodeJS to webassembly and being able to run NodeJS inside of the browser, Super cool!

I would like to do the same!

dose anyone have any instruction of how i can compile nodejs to Wasm?

Node.js version

Not applicable.

Example code

No response

Operating system

Not applicable.

Scope

runtime

Module and version

Not applicable.

Activity

  1. devsnek commented on Mar 7, 2022

    @devsnek
    Member

    My understanding is that they compiled the core nodejs logic to wasm and stubbed out other stuff (like V8) with fake functions that use browser apis. You'd have to ask them for more details.

  2. added
    answered🎉 Yay! The issue has been resolved, or the question has been answered.
    on Mar 21, 2022
  3. 0x7063 commented on Jul 5, 2022

    @0x7063

    @jimmywarting have you found any way to do it ?

  4. jimmywarting commented on Jul 5, 2022

    @jimmywarting
    Author

    nope

  5. zhujierong commented on Aug 30, 2022

    @zhujierong

    I also want to know

  6. lemanschik commented on Dec 10, 2022

    @lemanschik

    @devsnek your correct i did in fact hear from that guys before some days the first time they created a wasm build and then they use the memory pointers to the wasm worker to link the functions.

    https://w-corp.staticblitz.com/webcontainer-api-client.8cf5a3c77f45c942df800a39619ec49fff7e5814.js

    i am working on open sourcing stackblitz complet as they did copyed from nodejs and chromium anyway and we can come up with something better i did started to blame them on discord for not making that public.

    would have saved me a lot of time and the other people in the ecosystem:

    https://discord.com/channels/364486390102097930/680953097354215446

    they only want to make money they do not mention correct licenses and they claim they are more clever then the chromium team that triggered many so much that there will happen something then in fact they are simply not clever.

  7. lemanschik commented on Dec 10, 2022

    @lemanschik

    running nodejs as wasm modules is the right thing to do anyway the most time only fs and net is needed and stdio that are the core interfaces.

    • net

    • fs

    • stdio

    • crypto is in all environments already

    • net is in all environments but not all protocols we need to port from curl

    we in fact demonstrated that via the just-js project where v8 builds v8 with its modules independent maybe that can get turned into a wasm build the most things that they did is the network layer over the serviceWorker thats it.

    we do not even need that hackish stuff we have directly file system access api and we have direct sockets api both form the links to fs and net.

    while fs on linux for example also already leads alone to full network access as every device is a file you can write directly to sockets and devices.

    i can supply the needed browser apis to implement vm and such stuff including atomic workers and that.

    we run rollup and adapt the result of that as build cache

    node -e 'console.log(process.binding("natives"))'
    

    that are node js internals as js strings already formatted as object no need to use the files .

  8. lemanschik commented on Dec 10, 2022

    @lemanschik

    it was a big hoax they created a webcontainer lib and then built it into nodejs as wasm build to have something to bind against.

    i have condense the feature set of them it was

    • monaco-editor
    • offering running node commands but not really
    • then using vercel/trubo as npm implementation build as wasm but it does not matter rollup is better.
    • so conclusion you can run no native modules with that wasm build as they need to add them to the stack.
    • that all together reduces it into a npm compat layer for web projects to show a preview in the browser with the monaco-editor
    • they also aim to run servers via a custom network stack which are in fact only http servers which can get implemented

    the below is copyed out of the discord channel general chat

    your new marketing manager will have a hard job
    i will learn a lot if he can fix that as i am also company consultant it is a interristing case
    you just started up to get cash with a bad intend from the ground up
    i guess first thing on the roadmap was the licensing part
    as i can see
    thats why you did not mention the tech you depend on you tought ah we rust code a module call it webcontainer then we bind everything against that and say we have uniq tech
    SP33D — heute um 15:44 Uhr
    all who want to migrate should use github codespaces and the codespaces-Contrib.codeswing
    extension simply type swing into the terminal that also includes liveshare already
    it is the successor of this here
    you can use rollup to drop you npm tasks complet
    npm gets deprecated anyway by esmodules
    same principles as used here with the sdk the package json gets a own module thats it
    will start now writing migration docs for stackblitz users
    including usage of a local installed nodejs version directly with the browser
    i do not even want to keep the web container api
    it is the most evil project ever saw in web history
    trying to encapsulate a whole ecosystem that is not yours
    SP33D — heute um 15:57 Uhr
    here is how you implement a http server like in the examples they post in how to run a server in the browser

        socket.on('data',/** @type {UInt8Array} */ data => {
            const [requestHeader, ...bodyContent] = data.toString().split('\r\n\r\n');
    
            const [firstLine, ...otherLines] = requestHeader.split('\n');
            const [method, path, httpVersion] = firstLine.trim().split(' ');
            const headers = Object.fromEntries(otherLines.filter(_=>_)
                .map(line=>line.split(':').map(part=>part.trim()))
                .map(([name, ...rest]) => [name, rest.join(' ')]));
    
            var body;
            try {
                body = JSON.parse(bodyContent);
            } catch(err){/* ignore */}
    
    
            const request = {
                method, 
                path,
                httpVersion,
                headers,
                body
            };
            console.log(request)
            socket.write(`HTTP/1.1 200 OK\n\nhallo ${request.body.name}`)
            socket.end((err)=>{console.log(err)})
        });
    });

    this is a full fledged json powered http backend based on any socket that you like
    http is a pure string protocol
    so it is a little bit of utf 8 text interpreted
    you do not need anything more to return http responses and handle requests
    i could even make it a one liner in most cases this is only for education
    with webstreams i code that in 3 line blocks
    so this is enough to implement the express framework
    we have also added cool new regex features for that to ES2022
    look into the documentations
    thats why we write them
    and if you try to patent that then i get angry 🙂
    this allows you to even implement a http server via your favorit command line of choice as you can see the algo used to parse http
    the type of data if any one is wondering is UInt8Array
    buffers in the browser and nodejs are always UInt8Array based as ECMAScript is UTF8 based language

    imagin how fast server responses are if they come directly from a ecmascript worker
    not wasm
    do you want benchmarks?

    ffi-napi: 772.013ms
    sbffi: 29.467ms
    napi-addon: 3.790ms
    napi-addon-sb: 3.352ms
    wasm: 0.847ms
    js: 0.087ms
    

    10x faster my frinds
    take that

  9. lemanschik commented on Dec 10, 2022

    @lemanschik

    so i guess this can get closed as conclusion is building nodejs wasm is not usefull nowdays only to get npm compat

  10. image72 commented on Mar 3, 2023

    @image72
  11. moongazer07 commented on Nov 9, 2023

    @moongazer07

    @devsnek your correct i did in fact hear from that guys before some days the first time they created a wasm build and then they use the memory pointers to the wasm worker to link the functions.

    https://w-corp.staticblitz.com/webcontainer-api-client.8cf5a3c77f45c942df800a39619ec49fff7e5814.js

    i am working on open sourcing stackblitz complet as they did copyed from nodejs and chromium anyway and we can come up with something better i did started to blame them on discord for not making that public.

    would have saved me a lot of time and the other people in the ecosystem:

    https://discord.com/channels/364486390102097930/680953097354215446

    they only want to make money they do not mention correct licenses and they claim they are more clever then the chromium team that triggered many so much that there will happen something then in fact they are simply not clever.

    deobfuscation attempt
    attempt.txt

  12. lemanschik commented on Nov 10, 2023

    @lemanschik

    @moongazer07 thats not needed i have deobfusicated code and i did even more far dig into the weeds. It is even more simple there is no part from the binary libnode. It is only the internals folder so a shim environment. It is only JS => WASM

    We can archive 100% Feature Compatibility. In JS userland. Sure it would be more cool if we could simple compile the whole nodejs lib but it would add no benefits.

    the other part is the virtual terminal there xterm which is used in vscode would do the trick.

  13. github-actions commented on May 9, 2024

    @github-actions

    It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment.
    If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
    Make sure to look at the README file for the most updated links.

  14. github-actions commented on Jun 8, 2024

    @github-actions

    It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment.
    If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
    Make sure to look at the README file for the most updated links.

  15. 33 remaining items

  16. jswhisperer commented on Jun 7, 2025

    @jswhisperer

    @cheplv really interested to see your work especially the networking wrapper.

    I've seen some cool stuff allowing networking with PHP-Wasm
    https://github.com/WordPress/wordpress-playground/tree/trunk/packages/playground/php-cors-proxy
    and
    https://github.com/WordPress/wordpress-playground/tree/trunk/packages/php-wasm/node

  17. cheplv commented on Jun 8, 2025

    @cheplv

    @jswhisperer Yes, php was wasm compiled a long time ago - initially by vmware as I know

  18. jswhisperer commented on Jun 8, 2025

    @jswhisperer

    Ah totally I just meant that compiled PHP has managed network out of WASM whereas to my knowledge its not commonly available in any (node) js wasm solution yet, although https://webcontainers.io/ I think offer a paid feature of it, but being closed source it's probably just a real server proxy.

  19. gregnr commented on Jun 8, 2025

    @gregnr

    For in-browser networking I've been building tcpip.js which compiles the entire network stack to WASM (via lwIP). It allows you to hook into each layer of the stack (Ethernet, IP, TCP/UDP) based on your needs.

    It was originally built to communicate with in-browser VMs like v86, but might be useful here too!

  20. cheplv commented on Jun 8, 2025

    @cheplv

    @gregnr Thank you for great work. I use now tcpip js networking stack to run node in browser with DNS resolver )))
    But in future prefer to move on clear js stack like - https://github.com/Doridian/jsip

  21. gregnr commented on Jun 9, 2025

    @gregnr

    Great 🙂 would love to see it in action. I didn't write it from scratch in pure JS for a few reasons:

    • network protocols + extensions have evolved a lot over decades, so there's a lot to catch up to
    • lwIP is probably in the top 5-10 most used network implementations after the Linux/Windows/iOS kernels. It's used in lots of microcontrollers and IoT devices like ESP8266/ESP32 chips, so battle tested
    • lwIP is lightweight - compiles to less than 100KB of wasm, likely smaller/faster than the equivalent logic in pure JS
  22. cheplv commented on Jun 9, 2025

    @cheplv

    @gregnr Yes, this is good as a working net stack solution. Will keep you posted.
    BTW did you added dhcp client support?

  23. gregnr commented on Jun 9, 2025

    @gregnr

    BTW did you added dhcp client support?

    I have a DHCP POC, but it still needs more tests and docs:
    https://github.com/chipmk/tcpip.js/tree/main/packages/dhcp

  24. tonriderapp commented on Jun 13, 2025

    @tonriderapp

    hmmmm.
    I appreciate your efforts at work, but I don't understand your goals. Initially the community was interested in creating open source products, but you made an alternative product... for money. There is no point in using an alternative paid solution.

  25. jswhisperer commented on Jun 13, 2025

    @jswhisperer

    This might be useful https://github.com/wasmerio/wasmer-js haven't tested yet

  26. vickiegpt commented on Jun 14, 2025

    @vickiegpt

    https://github.com/vickiegpt/node some starting work here.

  27. makinghappen commented on Oct 26, 2025

    @makinghappen

    @vickiegpt any progess? there is no manual how to use..

  28. vickiegpt commented on Oct 26, 2025

    @vickiegpt

    @vickiegpt any progess? there is no manual how to use..

    nearly done. will be available on https://github.com/Multi-V-VM/codeapp

  29. avivkeller commented on Oct 26, 2025

    @avivkeller
    Member

    Hi! Let's keep discussion related to a particular topic within its own repository. Since this issue was closed a while ago, and current discussion appears off-topic to the resolution, I'm locking this.

  30. locked and limited conversation to collaborators on Oct 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    answered🎉 Yay! The issue has been resolved, or the question has been answered.stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions