I failed to run Dart on the web (but FYI you can run Linux on the web)
I had what I thought was a fun idea: what if you could compile and run Dart code entirely in the browser? No server, no cloud VM, just pure client-side execution.
The plan was simple:
- Use v86, a JavaScript x86 emulator, to boot Linux in the browser
- Use Monaco Editor for a nice code editing experience
- Download the Dart SDK into the virtual Linux environment
- Compile and run Dart code
I got steps 1 and 2 working. Step 3 is where it all fell apart.
What I Built
Here's the working prototype, the actual demo running live right here in this blog post:
Go ahead, try it. On the left, you have a code editor. On the right, a Linux terminal. Write a script, click "Run Script", and watch it execute in a real Linux environment, all running in your browser.
The fascinating part? That's not a terminal emulator pretending to be Linux. That's actual Linux. The output shows a real root filesystem with /bin, /dev, /proc, and all the standard directories you'd expect. (Open in a new tab if you prefer a full-page view.)
The v86 Magic
v86 is an x86 emulator written in JavaScript and WebAssembly. It can boot real operating systems: Linux, Windows 98, FreeDOS, and others. The emulation is accurate enough to run unmodified operating system images.
If you've never seen this before, take a moment to appreciate how wild it is. Your browser is running a complete x86 CPU emulation, which is running a Linux kernel, which is running a shell, which is executing your commands. All of this happens entirely client-side.
Why It Failed
The Dart SDK requires glibc (the GNU C Library). Most tiny Linux distributions use musl libc instead because it's much smaller. The distributions that support glibc are significantly larger and take much longer to boot.
I tried several approaches:
Alpine Linux: Fast and small, but uses musl. Dart doesn't work.
Buildroot with glibc: I could configure it to use glibc, but the resulting image was too large and boot times were unacceptable for a web demo.
Debian/Ubuntu minimal: Way too large. Boot times measured in minutes, not seconds.
The fundamental problem is that the Dart SDK is designed for real machines with real resources. It expects glibc, it expects fast disk I/O, and it expects more memory than a browser-based x86 emulator can reasonably provide.
What I Learned
Even though the project didn't achieve its goal, I found the exploration worthwhile.
v86 is impressive. The fact that you can boot Linux in a browser is remarkable. For educational purposes, lightweight Linux tools, or just showing off what WebAssembly can do, it's a fantastic project.
The web platform keeps surprising me. Between WebAssembly, SharedArrayBuffer, and modern JavaScript APIs, browsers can do things that would have seemed impossible a decade ago.
Some tools just aren't meant for constrained environments. The Dart SDK is designed for development machines. Trying to squeeze it into a browser-emulated Linux with limited resources was always going to be a stretch.
A Challenge
I'm setting this aside for now, but maybe you can get it to work. If you manage to get Dart running in the browser via v86 (or any other way), I'd love to hear about it.
Addendum: It was brought to my attention by Norbert Kozsir that Mike Diarmid managed to compile the Dart VM to WASM: see his tweet. Maybe he'll actually share his approach with the world? The challenge remains: there's no open source way to do this.
Links: