blog_hero_Offline Wails Development Guide

Offline Wails Development Guide

May 19 2023

Disclaimer: I LOVE wails, it's honestly a fantastic product and I've used it a lot for one-off products. This did however waste like 3 days of my time. When I unexpectedly had to rebuild the go environment on the offline side of my development.

So you want to use Wails offline? I will try my damnedest to help you succeed in this endeavor. I am unfortunately chained a desk to produce programs/products/code (whatever you think our trade does) without any internet access, so getting an offline environment setup for each particular creation is very important and I hate wasting time on it.

Things I assume you know I assume you know how to use a terminal, can successfully install stuff by reading a guide, and can follow along with the pictures :) (send me an email if you need more help).

Follow the guide to install Wails -> here

On a debian based machine it looks like this... (heed the warning about wails not being found!) Wails Install Example

resolve your dependencies based upon your system's package manager or whatever, the command I had to run to resolve everything was.

sudo apt install libgtk-3-dev libwebkit2gtk-4.0-dev pkg-config

It should eventually look like this when you run wails doctor

Wails Success Example

Okay, we are cooking with crisco now. Follow the "Creating a Project" page in the wails docs -> here.

Basically we slam in this series of commands:

mkdir ~/Code
cd ~/Code
wails init -n someprojectname -t vue-ts

I'm partial to typescript what can I say.

Typescript Wails Init

Run yourself a go mod tidy and a go mod vendor for good measure. Since you've obviously read the official docs and it seems to imply that if you run go mod vendor you won't need any other repository of the modules in order to build your program (this is sarcasm).

Go Mod Tidy and Vendor

So you take all those files you've made, and the vendor directory you so lovingly watched get crafted, and you transfer it to your offline machine, something that cannot possibly resolve any URL on the big ol' internet.

What happens when you run wails build on that machine would you guess? Would you assume that wails works as golang intended and correctly resolves the dependencies in the vendor folder (since it exists) and doesn't need to run go mod tidy and reach out to the web?

NOPE! Your offline machine's $GOMODCACHE directory is empty, since you did a fresh install of golang on it with whatever installer you used, and since you can't download anything the mod cache is empty. So when you run

wails build

It's going to look like this

Wails Fails

Now, there are two relatively simple solutions to this problem, one of them is worse than the other but both will get the job done.

Solution #1

Transfer your $GOMODCACHE directory from the online machine to the offline machine.

The only hang-up with this solution is that you need to either have the exact same output from "go env" on both machines and then just place the whole $GOMODCACHE directory in the same spot or you can manually alter the paths to have a centralized repository on the machine and just paste all of your $GOMODCACHE from the online machine to the offline machine. I feel as if this is the worse solution.

Go Env Example

Solution #2

When you build your project, run it with the -m flag (to skip go mod tidy)

wails build -m

We Can Build!!

Now we have successfully built a Wails program offline without an issue! There is no official mention of "vendor" or "offline development" in wails docs so I had to keep looking for stuff around the web. This was incredibly cathartic to type out so I might keep doing stuff like this in the future.

Wails docs?

Here are some useful links I did use in solving this