rollup-cache
raw JSON → 2.0.0 verified Mon Apr 27 auth: no javascript
Caching utilities for Rollup build plugins. Current version 2.0.0 requires Rollup v3 (breaking change from v1.x which targeted Rollup v2). Provides cacheConfig() and Cache class to persist and reuse expensive computation results across builds, improving incremental build performance. Key differentiator: designed specifically for Rollup plugin ecosystem with cache key generation and invalidation similar to Rollup's own caching. Releases are infrequent; maintenance seems low. Ships TypeScript types. ESM and CommonJS builds available.
Common errors
error Cannot find module 'rollup-cache' or its corresponding type declarations. ↓
cause Missing npm install or wrong module resolution: package.json 'exports' field may not cover all entry points.
fix
Ensure rollup-cache is installed: npm install rollup-cache. Use import from 'rollup-cache' not a subpath.
error rollup-cache: Rollup version mismatch. Expected >=3.0.0, got 2.x. ↓
cause Using rollup-cache v2 with Rollup v2.
fix
Upgrade Rollup to v3 or downgrade rollup-cache to v1.x: npm install rollup-cache@1
error export 'Cache' (imported as 'Cache') was not found in 'rollup-cache' ↓
cause Importing 'Cache' as a named export from a version that doesn't have it (pre-v1.1.0).
fix
Upgrade to rollup-cache v1.1.0 or later: npm install rollup-cache@latest
Warnings
breaking v2.0.0 requires Rollup v3; not compatible with Rollup v2. ↓
fix Use rollup-cache v1.x with Rollup v2, or upgrade Rollup to v3.
deprecated v1.2.0 introduced CommonJS build but type definitions may not resolve correctly in all CJS setups. ↓
fix Use ESM import to avoid type resolution issues, or pin exact version.
gotcha Cache is not a named export in v1.x? It was added in v1.1.0? Verify exports per version. ↓
fix Upgrade to v1.1.0 or later, or use internal cache manually.
Install
npm install rollup-cache yarn add rollup-cache pnpm add rollup-cache Imports
- cacheConfig wrong
const { cacheConfig } = require('rollup-cache')correctimport { cacheConfig } from 'rollup-cache' - Cache wrong
import Cache from 'rollup-cache'correctimport { Cache } from 'rollup-cache' - RollupCachePluginOptions
import type { RollupCachePluginOptions } from 'rollup-cache'
Quickstart
import { cacheConfig, Cache } from 'rollup-cache';
const cache = new Cache();
const rollupConfig = {
input: 'src/index.js',
output: { file: 'dist/bundle.js', format: 'esm' },
plugins: [
{
name: 'my-plugin',
resolveId(id) {
if (id === 'virtual-module') {
return '\0virtual';
}
return null;
},
load(id) {
if (id === '\0virtual') {
const cached = cache.get(id);
if (cached) return cached;
const code = 'export default 42;';
cache.set(id, code);
return code;
}
return null;
}
},
cacheConfig({ cache })
]
};
export default rollupConfig;