Registry / testing / rollup-plugin-memfs

rollup-plugin-memfs

JSON →
library4.0.1-alpha.0jsnpmunverified

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.

npm install rollup-plugin-memfs
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-MEMF
R
rollup-plugin-memfs
testingjavascriptv4.0.1-alpha.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

memfsPlugin
import { memfsPlugin } from 'rollup-plugin-memfs'
const memfsPlugin = require('rollup-plugin-memfs')
Package is ESM-only since v4. CommonJS require will fail.
createFs
import createFs from 'memfs/lib/promises'
import { createFs } from 'memfs'
The createFs function is a default export from memfs/lib/promises, not a named export from 'memfs'.
Volume
import { Volume } from 'memfs'
import Volume from 'memfs'
Volume is a named export from '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();
Debug
Known issues
breakingPackage 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.
affects: >=4.0.0
deprecatedmemfs v3 is deprecated; memfs v4 changes the filesystem API.
fix
Use memfs v4 and its Promise-based API: import createFs from 'memfs/lib/promises'.
affects: >=4.0.0
gotchaThe plugin requires memfs as a peer dependency, but it is not listed in package.json dependencies.
fix
Install memfs separately: npm install memfs
affects: >=1.0.0
gotchaRollup'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); }
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'rollup-plugin-memfs'
Package is ESM-only; using require() instead of import.
fix
Switch to ESM: use import or set type:"module" in package.json.
TypeError: memfsPlugin is not a function
Incorrect import: default import used when only named export exists.
fix
Use named import: import { memfsPlugin } from 'rollup-plugin-memfs'.
Error: ENOENT: no such file or directory, open '/index.js'
The file path does not exist in the memfs volume.
fix
Add the file to the volume: vol.fromJSON({'/index.js': 'content'}).
Upgrade
Version history
4.0.1-alpha.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
rollup-plugin-memfs — npm install rollup-plugin-memfs · libregistry