Currently viewing the AI version
Switch to human version

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' vs import { 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

  1. Create minimal config with single plugin
  2. Add plugins one by one until failure
  3. 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 used npm install instead of npm 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)

  1. rollup-plugin-visualizer: Size relationships
  2. webpack-bundle-analyzer: Interactive treemap
  3. 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

  1. Deploy source maps to private URL
  2. Add source map comment to production bundle
  3. 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

  1. Parallel Processing: Enable TypeScript transpileOnly, use all CPU cores for Terser
  2. Split Build: Type check separately from bundling
  3. 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

LinkDescription
rollup-plugin-visualizerShows what's eating your bundle size. Essential for production debugging.
Bundle BuddyUpload your source map, see why each module was included. Saves hours of guessing.
madgeFind circular dependencies that break builds. Run this first when builds hang.
npm-check-updatesCheck for outdated dependencies causing compatibility issues.
source-map-cliDecode source maps to find real error locations in production.
Rollup Troubleshooting GuideOfficial guide covers common configuration issues and plugin conflicts.
Rollup GitHub IssuesSearch existing issues before opening new ones. Most problems have been solved.
Plugin Development GuideUnderstand how plugins work to debug plugin conflicts and ordering issues.
Node.js Memory ManagementOfficial Node.js guide to debugging memory issues and heap problems.
Chrome DevTools Memory TabProfile memory usage during builds. Essential for tracking down leaks.
Clinic.jsAdvanced Node.js performance profiling. Overkill for most projects but powerful.
GitHub Actions DebuggingEnable debug logging to see what's happening in CI builds.
Vercel Build LogsUnderstanding Vercel's build process and memory limits.
Docker Node.js Best PracticesAvoid common Docker + Node.js pitfalls that break Rollup builds.
@rollup/plugin-commonjs IssuesMost CommonJS plugin problems have been reported. Search here first.
TypeScript Plugin DocsConfiguration options for the TypeScript plugin and known limitations.
Babel Plugin ConfigurationBabel + Rollup integration guide with working examples.
Webpack Bundle AnalyzerWorks with Rollup bundles too. Different visualization than rollup-plugin-visualizer.
bundlephobia.comCheck package sizes before importing. Prevent bundle bloat before it happens.
size-limitSet bundle size limits in your CI. Catches size regressions automatically.
Stack Overflow - Rollup TagSearch here first. Most production issues have solutions already.
Dev.to JavaScript TagAsk for help with complex bundling issues. Community is helpful with debugging.
Rollup DiscordActive community for real-time help. Good for urgent production issues.
ViteUses Rollup for production but handles development better. Consider switching if development builds are problematic.
esbuildMuch faster builds, less optimization. Good for when Rollup is too slow.
SWCRust-based alternative to Babel. Can speed up builds significantly.
Sentry Performance MonitoringTrack bundle performance impact on real users. Catch issues before users complain.
BundlewatchCI tool that fails builds if bundle size increases too much.
Bundle Size GitHub ActionAutomatically comment on PRs with bundle size changes.
MDN Web PerformanceUnderstanding how bundle size and loading affect user experience.
web.dev PerformanceGoogle's guide to web performance optimization and measurement.
Rollup Starter TemplatesWorking configurations for common project types. Copy these when starting over.
Awesome RollupCurated list of Rollup resources, plugins, and examples.
Real-world Rollup ConfigsSearch GitHub for working configurations from real projects.

Related Tools & Recommendations

compare
Recommended

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

Vite
/compare/vite/webpack/turbopack/esbuild/rollup/performance-comparison
100%
howto
Recommended

Converting Angular to React: What Actually Happens When You Migrate

Based on 3 failed attempts and 1 that worked

Angular
/howto/convert-angular-app-react/complete-migration-guide
41%
howto
Recommended

Migrating CRA Tests from Jest to Vitest

integrates with Create React App

Create React App
/howto/migrate-cra-to-vite-nextjs-remix/testing-migration-guide
40%
integration
Recommended

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

Vite
/integration/vite-react-typescript-eslint/integration-overview
40%
alternatives
Recommended

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
/alternatives/webpack/modern-performance-alternatives
28%
tool
Recommended

Webpack Performance Optimization - Fix Slow Builds and Giant Bundles

competes with Webpack

Webpack
/tool/webpack/performance-optimization
28%
tool
Recommended

esbuild - An Extremely Fast JavaScript Bundler

esbuild is stupid fast - like 100x faster than webpack stupid fast

esbuild
/tool/esbuild/overview
27%
tool
Recommended

esbuild Production Optimization - Ship Fast Bundles That Don't Suck

Fix your bloated bundles and 45-second build times

esbuild
/tool/esbuild/production-optimization
27%
tool
Recommended

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

SvelteKit
/tool/sveltekit/authentication-troubleshooting
27%
tool
Recommended

Svelte - The Framework That Compiles Away

JavaScript framework that builds your UI at compile time instead of shipping a runtime to users

Svelte
/tool/svelte/overview
27%
integration
Recommended

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

Svelte
/integration/svelte-sveltekit-tailwind-typescript/full-stack-architecture-guide
27%
tool
Recommended

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

Parcel
/tool/parcel/overview
26%
tool
Recommended

TypeScript - JavaScript That Catches Your Bugs

Microsoft's type system that catches bugs before they hit production

TypeScript
/tool/typescript/overview
26%
pricing
Recommended

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.

TypeScript
/pricing/typescript-vs-javascript-development-costs/development-cost-analysis
26%
tool
Recommended

JavaScript to TypeScript Migration - Practical Troubleshooting Guide

This guide covers the shit that actually breaks during migration

TypeScript
/tool/typescript/migration-troubleshooting-guide
26%
tool
Recommended

Turbopack - Finally, a bundler that doesn't suck

alternative to Turbopack

Turbopack
/tool/turbopack/overview
24%
review
Recommended

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

Vite
/review/vite-webpack-turbopack/performance-benchmark-review
24%
tool
Recommended

Vue.js - Building UIs That Don't Suck

The JavaScript framework that doesn't make you hate your job

Vue.js
/tool/vue.js/overview
24%
alternatives
Recommended

Fast React Alternatives That Don't Suck

compatible with React

React
/alternatives/react/performance-critical-alternatives
24%
integration
Recommended

Stripe Terminal React Native Production Integration Guide

Don't Let Beta Software Ruin Your Weekend: A Reality Check for Card Reader Integration

Stripe Terminal
/integration/stripe-terminal-react-native/production-deployment-guide
24%

Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization