Creating standalone Windows exes for Node CLI apps

Chris Bowdon
Jul 22, 2017 · 3 min read

I wrote a non-critical helper tool the other day and decided that it’d be easier to throw it together in Node than anything else. This turned out to be almost correct.

The sticking point was that I couldn’t expect my colleagues to have Node installed, so it had to be distributed as a standalone executable. No problem, we have NPM, infinite well of 80% solutions. Surely one of them will do the job.

I got there in the end, but it was such a PITA that it’s worth documenting for future travellers.

It turns out that there aren’t that many options if you want to create a non-GUI exe from a Node app. There were really only two: JXCore and nexe.

JXCore was unmaintained, but looked perfect nonetheless: it’s a single command that rapidly devoured my code and node modules, and spat out an executable. But when I tried to run the executable it fell over on “syntax errors”. Apparently JX bundles your code with Node 0.10, which doesn’t know ES2015. I could compile my code (and my dependencies) to ES5, but chances are the Node API has also broken in that time and there’ll be no way around that. So avoid JXCore.

How about nexe? It looks swish enough, but is a bit light on documentation.

More urgently, I couldn’t even get it installed. It seems NPM 5 has a fair few bugs, one of which being that Windows installs sometimes hang. So I had to downgrade to 4.6.1 temporarily to install it.

nexe has a usage statement, instructing you to pass input and output flags. This is not helpful because it doesn’t work — nexe will bomb out saying it was set up to use package.json variables, and can’t find them. If you plug in the example package.json setup from the README it will work though. Note that it’s from the V1 README, not the current V2 beta.

The next hurdle was that it compiles Node from source. On Windows this means you need Python 2 and Visual Studio 2015.

I had these, and it still didn’t work. Apparently my VS installation didn’t include the Visual C++ compiler. It had gigabytes of Windows Phone SDKs and obscure Azure Data Report Insight Synergy Business Power libraries, which I could not remove, but no C++ compiler. Strange.

Said compiler refuses to install on its own if it detects VS, so you need to go into Add/Remove Programs in the Control Panel and Change your VS installation to add features. I selected all the C++ ones, sat through a lengthy loading bar and reboot… and it still didn’t have the right compiler. So I tried again selecting all programming language-related features and finally there’s a successful compilation.

Great, end of story, well done, celebratory coffee? Nope, it bombs out on a Reference Error. Commiseration coffee instead.

The reference error came from one of the dependencies. It was evidently not “use strict” friendly (and despite me removing the option from the nexe config, strict mode was enforced).

I had to fork that library and fix the reference errors before it would finally work. Jeez-that-was-harder-than-expected coffee time.

Chris Bowdon

Written by

Physicist-turned-software-engineer. Fingers in many pies: Clojure, Emacs, JavaScript, Python, DevOps, GNU/Linux or as I’ve taken to calling it, GNU+Linux.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade