moeru-ai/airi · error · Error

Extension package exceeds the 512 MiB size limit.

Error message

Extension package exceeds the 512 MiB size limit.

What it means

During the walk, each regular file's size is accumulated; once the total exceeds extensionPackageLimits.totalBytes (512 MiB) the import is aborted. The cap bounds memory and copy cost of staging an extension package.

Solutions

  1. Remove large non-essential files (videos, weights, archives) from the folder.
  2. Exclude .git, node_modules, and build caches before importing.
  3. Compress or minify large assets, or reference them by URL instead of bundling.
  4. Split the package: keep the extension code small and host heavy assets separately.

Example fix

// before
await staged('my-ext/') // contains 800 MiB of model weights -> throws
// after
// rm my-ext/weights.bin; host weights remotely
await staged('my-ext/')
Defensive patterns

Strategy: validation

Validate before calling

import { readdir, stat } from 'node:fs/promises'
import { join } from 'node:path'
async function totalBytes(dir: string): Promise<number> {
  let total = 0
  for (const entry of await readdir(dir, { withFileTypes: true })) {
    const p = join(dir, entry.name)
    if (entry.isFile()) total += (await stat(p)).size
    else if (entry.isDirectory()) total += await totalBytes(p)
  }
  return total
}
// totalBytes(folder) must stay under 512 MiB (extensionPackageLimits.totalBytes)

Try / catch

try {
  await staged(folder)
} catch (error) {
  if (error instanceof Error && error.message.includes('512 MiB')) {
    showUserError('Package is too large; remove or externalize large assets.')
    return
  }
  throw error
}

Prevention

When it happens

Trigger: Calling inspectExtensionDirectory on a folder whose cumulative regular-file byte size exceeds 512 MiB.

Common situations: Accidentally importing a folder that contains large build artifacts, videos, model weights, or bundled binaries; including node_modules or .git packs; shipping unoptimized assets alongside the extension code.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of moeru-ai/airi@438a067dde (2026-09-17). Data as JSON: /api/errors/7eccf6bdfbc00c17. Report an issue: GitHub.

Appendix: source

Thrown at apps/stage-tamagotchi/src/main/services/airi/plugins/host/directory-import.ts:195

      }
      const path = join(directory, entry.name)
      const stats = await lstat(path)
      const relativePath = relative(sourceRealPath, path)

      if (stats.isSymbolicLink()) {
        throw new Error(`Extension packages cannot contain symbolic links: ${relativePath}`)
      }
      if (stats.isDirectory()) {
        directories.push(relativePath)
        pendingDirectories.push(path)
        continue
      }
      if (!stats.isFile()) {
        throw new Error(`Extension packages can contain only files and directories: ${relativePath}`)
      }
      totalBytes += stats.size
      if (totalBytes > extensionPackageLimits.totalBytes) {
        throw new Error('Extension package exceeds the 512 MiB size limit.')
      }
      files.push({ path, relativePath, size: stats.size })
    }
  }

  directories.sort()
  files.sort((left, right) => left.relativePath.localeCompare(right.relativePath))

  const manifestRelativePath = relative(sourceRealPath, manifestPath)
  const manifestFile = files.find(file => file.relativePath === manifestRelativePath)
  if (!manifestFile) {
    throw new Error(`Extension manifest does not exist: ${manifestPath}`)
  }
  if (manifestFile.size > extensionPackageLimits.manifestBytes) {
    throw new Error('Extension manifest exceeds the 1 MiB size limit.')
  }

  // The manifest remains the only retained byte snapshot because the preview

View on GitHub (pinned to 438a067dde)