Install Rollup 4.0 and check dependencies

Start by updating your project to the latest Rollup version. The current stable release is 4.60.4, published recently to npm. This version includes significant performance improvements and bug fixes that make the migration worthwhile.

1
Update Rollup in your project

Run the following command in your terminal to install the latest version:

Shell
Shell
npm install rollup@latest --save-dev

If you use Yarn, run:

Shell
Shell
yarn add rollup@latest --dev

This replaces your existing Rollup version with the latest one. Verify the installation by checking the version number:

Shell
Shell
npx rollup --version

This command should output the version number, confirming that the update was successful.

2
Verify Node.js version

Ensure your Node.js version is 18 or higher by running:

Shell
Shell
node --version

If your version is lower, update Node.js using a version manager like nvm or by downloading the latest LTS version from the official Node.js website.

3
Check for breaking changes

Review your rollup.config.js file for any deprecated options or syntax that may no longer be supported in Rollup 4.0. Common issues include:

  • Removed plugins or options
  • Changes in the output format configuration
  • Updates to the plugin API

Refer to the Rollup migration guide for a detailed list of breaking changes and how to update your configuration.

After updating, run your build process to ensure everything works as expected. If you encounter any errors, refer to the Rollup documentation or community forums for troubleshooting tips.

Update rollup.config.js for new syntax

Rollup 4.0 removes several deprecated options that were flagged in version 3. If your configuration still uses them, the build will fail immediately. You need to open rollup.config.js and replace these legacy properties with their modern equivalents.

The most common breaking change involves the output.format property. In previous versions, you could use shorthand strings like 'es' or 'cjs'. Rollup 4.0 now requires the full string values 'esm' and 'cjs'. This is a simple find-and-replace task, but it is mandatory for the build to run.

Another significant change is the removal of the inlineDynamicImports option. If you were using this to bundle all dynamic imports into a single file, you must now use the manualChunks option or configure your output format to handle imports differently. For most library projects, removing this option is safe because Rollup 4 handles dynamic imports more efficiently by default.

Finally, check for any usage of treeshake.pureExternalModules. This option has been removed. If you were using it to eliminate side-effect-free external modules, you should now rely on the default tree-shaking behavior or explicitly mark those modules in your package.json.

1
Replace format shorthands

Open your rollup.config.js file. Search for format: 'es' and change it to format: 'esm'. Do the same for format: 'cjs', changing it to format: 'cjs'. This ensures compatibility with the new parser.

2
Remove inlineDynamicImports

Locate the inlineDynamicImports property in your configuration object. Delete this line entirely. Rollup 4.0 manages dynamic imports without this explicit flag, simplifying your config file.

3
Update tree-shaking settings

Find treeshake.pureExternalModules in your config. Remove this property. If you relied on it to reduce bundle size, verify your build output to ensure no critical code was accidentally stripped. The default behavior is usually sufficient.

4
Verify the build

Run npm run build to test your configuration. If the build succeeds, your migration is complete. If you see errors about missing plugins or invalid options, check the Rollup 4.0 migration guide for specific plugin updates.

Fix plugin compatibility issues

Third-party plugins are the biggest hurdle when upgrading to Rollup 4. Many popular plugins haven't been updated to support the new internal API, causing immediate build failures. You need to audit your rollup.config.js before you even attempt to bump the version.

The most common breaking change is the removal of the this.resolveId context in plugins. If your plugin relies on resolving other modules during the build, it will fail unless you update the plugin structure. Check the Rollup 4 migration guide for specific API changes.

Identify outdated plugins

First, list all plugins in your project. Compare their current versions against the Rollup 4 changelog. If a plugin hasn't been updated in over a year, it is likely incompatible. Search for the plugin name followed by "Rollup 4" to see if a community fork exists.

Update plugin configurations

For plugins that have been updated, you may need to adjust your configuration. The transform hook signature has changed. Ensure you are passing the correct context object. Test each plugin individually by commenting out the rest of the config to isolate errors.

Handle deprecated hooks

Some plugins use deprecated hooks like load or resolveId in ways that are no longer supported. You must refactor these hooks to use the new async/await patterns. If a plugin is abandoned, look for a modern alternative that supports ES modules natively.

Test the build

Run npm run build after each plugin update. Fix errors one by one. Do not try to fix all errors at once. This step-by-step approach prevents confusion and helps you identify which plugin is causing the issue.

1
Audit your plugin list

Review your package.json and note all Rollup plugins. Check their GitHub repositories for recent commits or open issues related to Rollup 4.

2
Update compatible plugins

Run npm install <plugin-name>@latest for plugins that support Rollup 4. Verify the new version number in your package.json.

3
Refactor incompatible plugins

For plugins without updates, rewrite the hook logic to match the new API. If rewriting is too complex, replace the plugin with a compatible alternative.

4
Run the build

Execute npm run build. If it fails, check the error message for the specific plugin causing the issue. Repeat the audit and update process.

Run build and verify output

With the configuration updated, it is time to verify that the migration to Rollup 4.0 is complete. Run the build command to generate the final bundle. This step confirms that the new configuration syntax is valid and that the bundler can process your code without errors.

Shell
npm run build

Watch the terminal output closely. A successful build will end with a summary showing the output file paths and sizes. If the build fails, the error message will point to the specific line in your rollup.config.js that needs fixing. Common issues include invalid plugin names or missing output format definitions.

Once the build succeeds, inspect the generated bundle. Ensure the output matches your expectations for size and format. Rollup supports many output formats, including ES modules, CommonJS, and UMD. Verify that the bundle contains the expected exports and that no unexpected dependencies were included.

If the output looks correct, the migration is successful. If you encounter issues, check the Rollup documentation for troubleshooting tips related to the specific error code. A clean build is the final proof that your project is ready for the new version.

Compare Rollup 4.0 with Webpack

Choosing between Rollup 4.0 and Webpack depends on what you are building. Webpack is a general-purpose bundler designed for complex applications with many moving parts. Rollup is built specifically for libraries and small applications that prioritize small bundle sizes and tree-shaking efficiency.

If you are migrating a library to be distributed via npm, Rollup 4.0 is the better fit. It outputs clean ES modules or CommonJS files that integrate easily into other projects. Webpack tends to wrap libraries in its own runtime, which adds unnecessary overhead for consumers who just want to import a function.

Use the table below to see how they handle common bundling tasks. This comparison focuses on library distribution, which is the primary use case for Rollup 4.0.

FeatureRollup 4.0Webpack 5
Primary Use CaseLibraries & Small AppsComplex Applications
Tree-ShakingBuilt-in & EfficientRequires Configuration
Bundle SizeMinimal OverheadHigher Runtime Overhead
ConfigurationSimple & FlatComplex & Nested
Plugin EcosystemFocused & LightweightLarge & Extensive

For application development with heavy dynamic imports or complex asset pipelines, Webpack remains the standard. However, for static libraries where speed and size matter, Rollup 4.0 offers a lighter, more predictable build process. Stick with Rollup if your goal is to ship clean, dependency-free code to end users.

  • Verify your entry point is a single ES module file
  • Check that all dependencies are compatible with Rollup 4.0
  • Ensure your build script outputs the correct format (esm, cjs, or iife)
  • Test the generated bundle size against your Webpack baseline

Common rollup 4.0 migration: what to check next

Before you commit to the upgrade, it helps to clarify how Rollup 4.0 fits into your current stack. The changes are breaking, but they are also designed to make your build output smaller and faster. Here are the answers to the most frequent questions developers ask during this transition.

The migration process can feel daunting, but breaking it down into specific tasks makes it manageable. Follow the steps below to update your configuration and verify your build.