Rollup Production Troubleshooting: AI-Optimized Guide
Critical Memory Issues
JavaScript Heap Out of Memory
Failure Mode: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
Impact: Kills builds completely for large codebases
Quick Fix: NODE_OPTIONS="--max-old-space-size=8192" npm run build
Permanent Solution: Add to package.json scripts
Root Causes:
- Large TypeScript projects with complex type checking
- Circular dependencies creating memory loops
- Bad plugins not cleaning up properly
- Processing massive files (15MB+ JSON imports)
Build Hangs at 90% Completion
Symptoms: Build shows progress then freezes with no error output
Nuclear Option: rm -rf node_modules package-lock.json && npm install && npm run build
(works 90% of time)
Smart Debugging: Use madge --circular --format es6 src/
to detect circular dependencies
Common Causes:
- Circular imports creating infinite loops
- Plugin conflicts (especially TypeScript + Babel)
- Corrupted node_modules cache
- File watchers on Windows getting confused
Bundle Size Explosions
Immediate Diagnosis Tool
Essential Plugin: rollup-plugin-visualizer
import { visualizer } from 'rollup-plugin-visualizer';
plugins: [
visualizer({
filename: 'dist/stats.html',
open: true,
gzipSize: true
})
]
Common Size Killers
- moment.js import: Adds 500KB (use date-fns instead)
- Wrong lodash import:
import _ from 'lodash'
vsimport { debounce } from 'lodash-es'
- Dev dependency leak: Check external configuration
- Broken tree-shaking: Side effects not properly marked
Real Impact: Bundle went from 300KB to 3MB, site became unusable until fixed
Plugin Configuration Hell
Working Plugin Order (95% of projects)
plugins: [
resolve({ preferBuiltins: false }),
commonjs(),
typescript(),
babel(),
terser() // Always last
]
Plugin Conflict Debugging Strategy
- Create minimal config with single plugin
- Add plugins one by one until failure
- Test in isolation with separate config file
Known Plugin Issues
- @rollup/plugin-commonjs: Gives up on weird packages (react-dom)
- @rollup/plugin-typescript: Ignores half of tsconfig.json settings
- rollup-plugin-postcss: Breaks with CSS modules sometimes
- @rollup/plugin-json: Crashes on huge JSON files
CI/CD Failures
GitHub Actions Memory Issues
Solution: NODE_OPTIONS="--max-old-space-size=4096" npm run build
Root Cause: GitHub Actions default runners have memory limitations
Vercel Deployment Failures
Limit: 250MB for entire build directory
Check: du -sh dist/
to verify size locally
Docker Build Issues
FROM node:18-alpine
ENV NODE_OPTIONS="--max-old-space-size=4096"
RUN npm run build
Source Map Problems
Production Configuration
output: {
sourcemap: true,
sourcemapExcludeSources: true // Don't leak source code
}
Debugging Production Errors
Tool: smc --source-map dist/bundle.js.map --line 1 --column 47293
Integration: Sentry or Bugsnag for automated error tracking
Crisis Mode Solutions
Build Works Locally, Fails in CI
Primary Suspects: Node version differences, environment variables, dependency cache
Quick Fixes:
- Lock Node version with
.nvmrc
- Clear CI cache:
rm -rf node_modules package-lock.json && npm ci
- Check environment differences:
env | grep NODE
Root Cause 90% of time: Different dependencies (someone usednpm install
instead ofnpm ci
)
Bundle Loads But App Crashes
Diagnosis: Tree-shaking removed needed code or wrong module loading order
Quick Test: Set treeshake: false
temporarily
Look For:
- Side effects in imported modules
- Dynamic imports Rollup can't analyze
- Circular dependencies confusing module order
Memory Usage Growing on Rebuilds
Symptom: First build 2GB RAM, second build 4GB, eventually crashes
Known Issue: Rollup watch mode with certain plugins
Workarounds:
- Use Vite for development, Rollup for production
- Restart build process periodically
NODE_OPTIONS="--max-old-space-size=8192"
Module Not Found But File Exists
Usual Cause: Path resolution broken or mixing module systems
Debug Steps:
resolve({
preferBuiltins: false,
browser: true,
exportConditions: ['svelte'] // Adjust for framework
})
Check: Import paths, case sensitivity, missing file extensions
Advanced Debugging Techniques
Bundle Analysis Tools (Use All)
- rollup-plugin-visualizer: Size relationships
- webpack-bundle-analyzer: Interactive treemap
- Bundle Buddy: Explains why modules included
Memory Profiling
Heap Snapshots: node --inspect-brk node_modules/.bin/rollup -c
Memory Leak Detection: Use memwatch-next for monitoring
Real Example: 12GB RAM usage reduced to 2GB by updating TypeScript plugin
Performance Profiling
Build Time: ROLLUP_WATCH_INCLUDE_TIME=1 rollup -c --watch
Plugin Timing: Wrap plugins with timing measurements
Bottleneck Identification: Usually TypeScript or large file processing
Dependency Hell
Version Conflicts: npm ls --depth=0 | grep -E "├─|└─" | sort
Force Resolutions: Use overrides in package.json as last resort
Real Example: Three @babel/core versions caused random build failures
Production Runtime Errors
Source Map Debugging
- Deploy source maps to private URL
- Add source map comment to production bundle
- Use Chrome DevTools with source maps enabled
Error Tracking Integration
replace({
'__BUILD_DATE__': JSON.stringify(new Date().toISOString()),
'__GIT_COMMIT__': JSON.stringify(process.env.GIT_COMMIT || 'unknown')
})
Emergency Debugging
Chrome Works, Safari/Firefox Breaks
Cause: Modern JavaScript features need polyfills
Fix: Configure Babel with browser targets
Common Culprits: Optional chaining, nullish coalescing, dynamic imports
Slow Build Performance
- Parallel Processing: Enable TypeScript transpileOnly, use all CPU cores for Terser
- Split Build: Type check separately from bundling
- Cache Everything: Enable Rollup cache, TypeScript incremental builds
Nuclear Option: Use SWC instead of Babel (20x faster)
Code Splitting 404s
Problem: New chunk names, old chunks deleted
Solutions:
- Stable chunk names:
[name]-[hash].js
- Manual chunks for vendor libraries
- CDN cache invalidation after deploy
Plugin "Cannot Find Module"
First Try: Restart dev server (plugin resolution caches aggressive)
Nuclear Option: rm -rf node_modules package-lock.json .rollup.cache && npm install
Check: Plugin version compatibility
Wrong Source Map Lines
Cause: Minification scrambling mappings
Fix: Generate source maps at each transformation step
Debug: Use source-map-cli to validate mappings
Missing Features in Production
Cause: Tree-shaking killed important code
Quick Test: Set moduleSideEffects: true
Proper Fix: Mark side effects in package.json
"ReferenceError: exports is not defined"
Problem: Mixing CommonJS and ES modules incorrectly
Fix: Configure CommonJS plugin to only convert node_modules
Alternative: Convert everything to ES modules
Resource Requirements
Memory Allocation
- Development: 2-4GB sufficient for most projects
- Large Projects: 8GB+ required (TypeScript, large dependencies)
- CI Environments: 4GB recommended minimum
Build Time Expectations
- Small Projects (<100 files): 10-30 seconds
- Medium Projects (100-1000 files): 1-5 minutes
- Large Projects (1000+ files): 5-15 minutes
- Performance Issues: >15 minutes indicates problems
Expertise Requirements
- Basic Setup: Junior developer can handle with documentation
- Plugin Configuration: Mid-level developer needed
- Performance Optimization: Senior developer required
- Memory Debugging: Expert-level Node.js knowledge needed
Critical Warnings
Production Deployment
- Never commit without testing: Rollup's tree-shaking can break functionality
- Always run linting/type checking: Build success doesn't guarantee code quality
- Monitor bundle size: Set automated alerts for size increases
- Test in target browsers: Chrome success doesn't guarantee cross-browser compatibility
Configuration Pitfalls
- Plugin order matters: Wrong order causes mysterious failures
- Tree-shaking aggressive: Can remove needed code unexpectedly
- Source maps leak source: Use sourcemapExcludeSources in production
- Memory limits hit suddenly: Node.js default heap insufficient for large projects
Breaking Points
- >1000 TypeScript files: Memory issues likely without optimization
- >250MB build output: Vercel deployment fails
- Circular dependencies: Cause infinite loops and memory leaks
- Mixed module systems: CommonJS/ES modules mixing breaks builds
Decision Criteria
When to Use Rollup
- Library bundling: Excellent tree-shaking and ES module output
- Production optimization: Superior dead code elimination
- Plugin ecosystem: Extensive plugin availability
When to Avoid Rollup
- Large applications: Webpack better for app bundling
- Development speed priority: Vite/esbuild much faster
- Team expertise low: Steeper learning curve than alternatives
Alternative Considerations
- Vite: Better development experience, uses Rollup for production
- esbuild: Much faster, less optimization
- Webpack: Better for large applications, more mature ecosystem
- SWC: Rust-based, extremely fast, growing ecosystem
Emergency Resources
Essential Tools
- rollup-plugin-visualizer: Bundle size analysis
- Bundle Buddy: Module inclusion analysis
- madge: Circular dependency detection
- source-map-cli: Source map debugging
- npm-check-updates: Dependency updates
Documentation
- Rollup Troubleshooting Guide: Official configuration issues
- Plugin Development Guide: Understanding plugin conflicts
- Node.js Memory Management: Debugging memory problems
- Chrome DevTools Memory: Profiling memory usage
Community Support
- Rollup Discord: Real-time help for urgent issues
- Stack Overflow: Search existing solutions first
- GitHub Issues: Most problems already reported and solved
Useful Links for Further Investigation
Emergency Resources When Everything's Broken
Link | Description |
---|---|
rollup-plugin-visualizer | Shows what's eating your bundle size. Essential for production debugging. |
Bundle Buddy | Upload your source map, see why each module was included. Saves hours of guessing. |
madge | Find circular dependencies that break builds. Run this first when builds hang. |
npm-check-updates | Check for outdated dependencies causing compatibility issues. |
source-map-cli | Decode source maps to find real error locations in production. |
Rollup Troubleshooting Guide | Official guide covers common configuration issues and plugin conflicts. |
Rollup GitHub Issues | Search existing issues before opening new ones. Most problems have been solved. |
Plugin Development Guide | Understand how plugins work to debug plugin conflicts and ordering issues. |
Node.js Memory Management | Official Node.js guide to debugging memory issues and heap problems. |
Chrome DevTools Memory Tab | Profile memory usage during builds. Essential for tracking down leaks. |
Clinic.js | Advanced Node.js performance profiling. Overkill for most projects but powerful. |
GitHub Actions Debugging | Enable debug logging to see what's happening in CI builds. |
Vercel Build Logs | Understanding Vercel's build process and memory limits. |
Docker Node.js Best Practices | Avoid common Docker + Node.js pitfalls that break Rollup builds. |
@rollup/plugin-commonjs Issues | Most CommonJS plugin problems have been reported. Search here first. |
TypeScript Plugin Docs | Configuration options for the TypeScript plugin and known limitations. |
Babel Plugin Configuration | Babel + Rollup integration guide with working examples. |
Webpack Bundle Analyzer | Works with Rollup bundles too. Different visualization than rollup-plugin-visualizer. |
bundlephobia.com | Check package sizes before importing. Prevent bundle bloat before it happens. |
size-limit | Set bundle size limits in your CI. Catches size regressions automatically. |
Stack Overflow - Rollup Tag | Search here first. Most production issues have solutions already. |
Dev.to JavaScript Tag | Ask for help with complex bundling issues. Community is helpful with debugging. |
Rollup Discord | Active community for real-time help. Good for urgent production issues. |
Vite | Uses Rollup for production but handles development better. Consider switching if development builds are problematic. |
esbuild | Much faster builds, less optimization. Good for when Rollup is too slow. |
SWC | Rust-based alternative to Babel. Can speed up builds significantly. |
Sentry Performance Monitoring | Track bundle performance impact on real users. Catch issues before users complain. |
Bundlewatch | CI tool that fails builds if bundle size increases too much. |
Bundle Size GitHub Action | Automatically comment on PRs with bundle size changes. |
MDN Web Performance | Understanding how bundle size and loading affect user experience. |
web.dev Performance | Google's guide to web performance optimization and measurement. |
Rollup Starter Templates | Working configurations for common project types. Copy these when starting over. |
Awesome Rollup | Curated list of Rollup resources, plugins, and examples. |
Real-world Rollup Configs | Search GitHub for working configurations from real projects. |
Related Tools & Recommendations
Vite vs Webpack vs Turbopack vs esbuild vs Rollup - Which Build Tool Won't Make You Hate Life
I've wasted too much time configuring build tools so you don't have to
Converting Angular to React: What Actually Happens When You Migrate
Based on 3 failed attempts and 1 that worked
Migrating CRA Tests from Jest to Vitest
integrates with Create React App
Vite + React 19 + TypeScript + ESLint 9: Actually Fast Development (When It Works)
Skip the 30-second Webpack wait times - This setup boots in about a second
Webpack is Slow as Hell - Here Are the Tools That Actually Work
Tired of waiting 30+ seconds for hot reload? These build tools cut Webpack's bloated compile times down to milliseconds
Webpack Performance Optimization - Fix Slow Builds and Giant Bundles
competes with Webpack
esbuild - An Extremely Fast JavaScript Bundler
esbuild is stupid fast - like 100x faster than webpack stupid fast
esbuild Production Optimization - Ship Fast Bundles That Don't Suck
Fix your bloated bundles and 45-second build times
SvelteKit Authentication Troubleshooting - Fix Session Persistence, Race Conditions, and Production Failures
Debug auth that works locally but breaks in production, plus the shit nobody tells you about cookies and SSR
Svelte - The Framework That Compiles Away
JavaScript framework that builds your UI at compile time instead of shipping a runtime to users
SvelteKit + TypeScript + Tailwind: What I Learned Building 3 Production Apps
The stack that actually doesn't make you want to throw your laptop out the window
Parcel - Fucking Finally, A Build Tool That Doesn't Hate You
The build tool that actually works without making you want to throw your laptop out the window
TypeScript - JavaScript That Catches Your Bugs
Microsoft's type system that catches bugs before they hit production
Should You Use TypeScript? Here's What It Actually Costs
TypeScript devs cost 30% more, builds take forever, and your junior devs will hate you for 3 months. But here's exactly when the math works in your favor.
JavaScript to TypeScript Migration - Practical Troubleshooting Guide
This guide covers the shit that actually breaks during migration
Turbopack - Finally, a bundler that doesn't suck
alternative to Turbopack
Vite vs Webpack vs Turbopack: Which One Doesn't Suck?
I tested all three on 6 different projects so you don't have to suffer through webpack config hell
Vue.js - Building UIs That Don't Suck
The JavaScript framework that doesn't make you hate your job
Fast React Alternatives That Don't Suck
compatible with React
Stripe Terminal React Native Production Integration Guide
Don't Let Beta Software Ruin Your Weekend: A Reality Check for Card Reader Integration
Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization