Skip to content

Instantly share code, notes, and snippets.

@lcw99
Last active November 16, 2025 10:33
Show Gist options
  • Select an option

  • Save lcw99/596b7b4bb62c86531f3f410bd9d87dea to your computer and use it in GitHub Desktop.

Select an option

Save lcw99/596b7b4bb62c86531f3f410bd9d87dea to your computer and use it in GitHub Desktop.
Fixing Vercel Timeout and Size Errors When Deploying Flutter + Python Endpoints

Fixing Vercel Timeout and Size Errors When Deploying Flutter + Python Endpoints

The Problem

When deploying a Flutter web application alongside Python API endpoints to Vercel, you may encounter deployment failures with timeout errors or size limit errors like:

15:53:57.335  Compiling lib/main.dart for the Web...                             60.1s
15:53:57.336  ✓ Built build/web
15:53:59.154  No Python version specified in pyproject.toml or Pipfile.lock. Using latest installed version: 3.12
15:54:00.664  Installing required dependencies from requirements.txt...
15:54:00.665  Using uv at "/usr/local/bin/uv"
15:54:04.893  Build Completed in /vercel/output [3m]
15:54:05.828  Deploying outputs...
16:21:58.689  Error: Size of uploaded file exceeds 300MB

Note: Getting the size error is actually the "happy case" - most of the time you just get a timeout without any clear indication of what went wrong.

Root Cause

After building a Flutter application, the build process creates many folders and files in the Vercel working directory. When deploying Flutter alone as a static site, this isn't a problem because Vercel only deploys the output directory.

However, when you add other platforms like Python API endpoints, Vercel attempts to deploy all files in the working folder, not just your specified output directory. This causes:

  1. Timeouts - Too many files to process
  2. Size limit errors - Total size exceeds Vercel's 300MB deployment limit

The Solution

Add post-processing to your build script that deletes all folders and files except build/web (your Flutter output) and api (your Python endpoints).

Configuration Files

vercel.json

{
  "git": {
    "deploymentEnabled": {
      "main": false
    }
  },
  "installCommand": "sh install_flutter.sh",
  "buildCommand": "sh build_flutter.sh",
  "outputDirectory": "build/web"
}

install_flutter.sh

#!/bin/bash

# Install or update Flutter to specific version
FLUTTER_VERSION="3.35.7"

if cd flutter; then
  echo "Updating existing Flutter installation to version $FLUTTER_VERSION..."
  git fetch --tags
  git checkout $FLUTTER_VERSION
  git pull
  cd ..
else
  echo "Cloning Flutter and checking out version $FLUTTER_VERSION..."
  git clone https://github.com/flutter/flutter.git --branch stable
  cd flutter
  git checkout $FLUTTER_VERSION
  cd ..
fi

echo "Flutter files:"
ls

echo "Running Flutter doctor..."
flutter/bin/flutter doctor

echo "Cleaning Flutter build..."
flutter/bin/flutter clean

echo "Enabling web support..."
flutter/bin/flutter config --enable-web

echo "Getting Flutter dependencies..."
flutter/bin/flutter pub get

echo "Flutter installation complete!"

build_flutter.sh (The Key Solution)

#!/bin/bash

# Build Flutter web application for production

# Load environment variables
sh env.sh

# Build Flutter web with release configuration
flutter/bin/flutter build web --release

# Clean up: delete all files except build/web and api directories
find . -mindepth 1 -maxdepth 1 ! -name 'build' ! -name 'api' ! -name '.' -exec rm -rf {} +
find build -mindepth 1 -maxdepth 1 ! -name 'web' -exec rm -rf {} +

Key Lines Explained

The critical cleanup commands at the end of build_flutter.sh:

# Delete everything in root except 'build' and 'api' directories
find . -mindepth 1 -maxdepth 1 ! -name 'build' ! -name 'api' ! -name '.' -exec rm -rf {} +

# Inside 'build', delete everything except 'web' directory
find build -mindepth 1 -maxdepth 1 ! -name 'web' -exec rm -rf {} +

This ensures that after the build:

  • Only build/web (Flutter static files) remains
  • Only api/ (Python endpoints) remains
  • All other Flutter source files, dependencies, and build artifacts are removed

Result

With this cleanup in place, Vercel only deploys:

  • Your Flutter web application (build/web) as a static site
  • Your Python API endpoints (api/)

This keeps the deployment size small and prevents timeout errors, allowing successful deployment of both Flutter and Python on Vercel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment