apps/docs/content/troubleshooting/edge-function-dependency-analysis.mdx
Optimize your Edge Function dependencies for better performance. Large or unnecessary dependencies can significantly impact bundle size, boot time, and memory usage.
Start by analyzing your dependency tree to understand what's being imported:
# Basic dependency analysis
deno info /path/to/function/index.ts
# With import map (if using one)
deno info --import-map=/path/to/import_map.json /path/to/function/index.ts
Review the output for:
When using NPM modules, keep their impact on bundle size in mind. Many NPM packages are designed for Node.js and may include unnecessary polyfills or large dependency trees.
Import specific submodules to minimize overhead:
// Good: Import specific submodules
import { Sheets } from 'npm:@googleapis/sheets'
import { JWT } from 'npm:google-auth-library/build/src/auth/jwtclient'
// Avoid: Import entire package
import * as googleapis from 'npm:googleapis'
import * as googleAuth from 'npm:google-auth-library'
Only import what you actually use. Avoid wildcard imports (import *) when possible.
Research smaller packages that provide the same functionality. Consider:
Use deno info before and after changes to measure the impact of dependency modifications.
Lock dependency versions to avoid unexpected size increases from automatic updates:
// Pin to specific version
import { something } from 'npm:[email protected]'
Watch out for these commonly heavy packages:
date-fns) or native Date APIs)lodash/get)