help
help copied to clipboard
compile NodeJS to wasm
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.
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.
@jimmywarting have you found any way to do it ?
nope
I also want to know
@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.
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.
- [ ] https://github.com/lemanschik/web-modules/issues/7
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 .
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
so i guess this can get closed as conclusion is building nodejs wasm is not usefull nowdays only to get npm compat
try this npm package ? javy
JavaScript and WASI I turned JS into a compiled language (for fun and Wasm)
@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
@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.
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.
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.