rollup-plugin-memfs

raw JSON →
4.0.1-alpha.0 verified Mon Apr 27 auth: no javascript

A Rollup plugin that uses an in-memory filesystem (memfs) as the file system backend, enabling unit testing of Rollup builds without writing to disk. Current version is 4.0.1-alpha.0. It replaces Rollup's default file system with a memfs instance, allowing deterministic tests and fast iteration. Key differentiators: works with memfs v4, supports Promise-based memfs API, and is TypeScript-native. Compared to alternatives like rollup-plugin-mock-fs, this plugin integrates directly with memfs's Volume for fine-grained virtual file control.

error Error: Cannot find module 'rollup-plugin-memfs'
cause Package is ESM-only; using require() instead of import.
fix
Switch to ESM: use import or set type:"module" in package.json.
error TypeError: memfsPlugin is not a function
cause Incorrect import: default import used when only named export exists.
fix
Use named import: import { memfsPlugin } from 'rollup-plugin-memfs'.
error Error: ENOENT: no such file or directory, open '/index.js'
cause The file path does not exist in the memfs volume.
fix
Add the file to the volume: vol.fromJSON({'/index.js': 'content'}).
breaking Package renamed from 'rollup-plugin-memfs' to 'rollup-plugin-memfs' (no change, but major version bump to 4 changes API).
fix Update import to ESM: import { memfsPlugin } from 'rollup-plugin-memfs'. No more default export.
deprecated memfs v3 is deprecated; memfs v4 changes the filesystem API.
fix Use memfs v4 and its Promise-based API: import createFs from 'memfs/lib/promises'.
gotcha The plugin requires memfs as a peer dependency, but it is not listed in package.json dependencies.
fix Install memfs separately: npm install memfs
gotcha Rollup's onwarn option may ignore file system errors that are caught by memfs.
fix Set onwarn to log warnings: onwarn(warning, defaultHandler) => { console.warn(warning.message); }
npm install rollup-plugin-memfs
yarn add rollup-plugin-memfs
pnpm add rollup-plugin-memfs

Creates an in-memory filesystem with memfs, uses it as Rollup's file system, and generates a bundle without touching disk.

import { Volume } from 'memfs';
import createFs from 'memfs/lib/promises';
import { memfsPlugin } from 'rollup-plugin-memfs';
import { rollup } from 'rollup';

const vol = Volume.fromJSON({
  '/input.js': 'export default 42;'
});
const memfs = createFs(vol);

async function build() {
  const bundle = await rollup({
    input: '/input.js',
    plugins: [memfsPlugin(memfs)]
  });
  const { output } = await bundle.generate({ format: 'es' });
  console.log(output[0].code); // 'var input = 42; export { input as default };'
}
build();