Back to Blog

Made an Electron app bigger than GTA 6 (by accident)

Desktop Development

GTA 6 needs up to 212 GB of free space on a console. I used 318 GB trying to put one file in a folder.

I found out while backing up my personal projects. My custom 7-Zip command skipped the stuff I could download again, but the scan still hit 619 GB. I have enough unfinished projects that I was willing to believe that number.

Then 7-Zip stopped. I recognized the Windows app in the last path it printed. A few folders further in, I recognized it again.

Windows app
└── helper folder
    └── Windows app
        └── helper folder
            └── …

About half the entire scan came from that one app’s build folder. I’d expected an installer of a few hundred megabytes, so I went back to see what I’d asked it to include.

I accidently told it to copy a folder into itself

The helper was a Python program. I kept it in a folder called dist and told electron-builder to copy that folder into the Windows app. The mistake is easier to see when you write out where the copy was going.

From   dist/
Into   dist/win-unpacked/resources/backend/

Both paths start with dist/. As soon as the packager created its destination, there was a new folder inside the one it was still copying. Follow that folder and it could pick up the copy it had just made. One trip through the same three folder names, then another.

One folder name, 1,054 times

My first guess was that I’d rebuilt the app about ten times and doubled its size each time. Then I asked PowerShell for the deepest directory it could find.

Occurrences of win-unpacked1,054
Parts in the full path3,168
Characters in the full path32,740

One bad build could explain all 1,054 levels. Divide the folder’s 296.48 GiB by that depth and it works out to about 288 MiB per level. That fits a single copy adding roughly one app’s worth of files each time it went a level deeper.

Room for 27 more characters

One more \resources\backend\win-unpacked would have added 31 characters, taking the path to 32,771. Microsoft puts the Windows extended-length path limit at about 32,767 characters.

My best guess is the build kept copying until Windows couldn’t fit another round of folder names. The scan shows how far PowerShell could follow it. I’d need the build error to say for sure what stopped it.

See the PowerShell depth check

From the project folder, I counted the parts of each directory’s full path, including the drive, and kept the deepest result. The scan skipped directories it couldn’t read.

Get-ChildItem .\dist -Recurse -Directory -Force -ErrorAction SilentlyContinue |
    ForEach-Object {
        [pscustomobject]@{
            Depth   = $_.FullName.Split('\').Count
            Repeats = ([regex]::Matches($_.FullName, 'win-unpacked')).Count
            Len     = $_.FullName.Length
        }
    } |
    Sort-Object Depth -Descending |
    Select-Object -First 1

Getting my disk space back

I gave finished builds their own folder and changed the copy rule to ask for the helper by name. That put the destination outside the folder being copied. The app itself still finds its helper in the same place.

Deleting the old copies took more work. The folders went so deep that Windows Explorer struggled to remove them. What finally worked was telling a Windows utility to make that build folder match an empty one.

See the exact fix in electron-builder

PyInstaller bundled the Flask backend as dist/app.exe. This was the part of package.json that told electron-builder to take the whole directory with it.

{
  "build": {
    "directories": { "output": "dist" },
    "extraResources": [
      { "from": "dist/", "to": "backend/", "filter": ["**/*"] }
    ]
  }
}

The resulting paths looked like this in the 7-Zip scan.

…\resources\backend\win-unpacked\resources\backend\win-unpacked\…

I changed the output directory to release and the copy rule to a single file. Electron could still launch the backend from the same place.

{
  "build": {
    "directories": { "output": "release" },
    "extraResources": [
      { "from": "dist/app.exe", "to": "backend/app.exe" }
    ]
  }
}

PowerShell counted 296.48 GiB of files under dist, or about 318 GB in decimal units. To remove the old files, I used robocopy /MIR with an empty directory as its source and this project’s disposable dist as its destination.