{"id":22125,"library":"rollup-plugin-memfs","title":"rollup-plugin-memfs","description":"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.","status":"active","version":"4.0.1-alpha.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install rollup-plugin-memfs","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-memfs","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-memfs","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only since v4. CommonJS require will fail.","wrong":"const memfsPlugin = require('rollup-plugin-memfs')","symbol":"memfsPlugin","correct":"import { memfsPlugin } from 'rollup-plugin-memfs'"},{"note":"The createFs function is a default export from memfs/lib/promises, not a named export from 'memfs'.","wrong":"import { createFs } from 'memfs'","symbol":"createFs","correct":"import createFs from 'memfs/lib/promises'"},{"note":"Volume is a named export from 'memfs'.","wrong":"import Volume from 'memfs'","symbol":"Volume","correct":"import { Volume } from 'memfs'"}],"quickstart":{"code":"import { Volume } from 'memfs';\nimport createFs from 'memfs/lib/promises';\nimport { memfsPlugin } from 'rollup-plugin-memfs';\nimport { rollup } from 'rollup';\n\nconst vol = Volume.fromJSON({\n  '/input.js': 'export default 42;'\n});\nconst memfs = createFs(vol);\n\nasync function build() {\n  const bundle = await rollup({\n    input: '/input.js',\n    plugins: [memfsPlugin(memfs)]\n  });\n  const { output } = await bundle.generate({ format: 'es' });\n  console.log(output[0].code); // 'var input = 42; export { input as default };'\n}\nbuild();","lang":"typescript","description":"Creates an in-memory filesystem with memfs, uses it as Rollup's file system, and generates a bundle without touching disk."},"warnings":[{"fix":"Update import to ESM: import { memfsPlugin } from 'rollup-plugin-memfs'. No more default export.","message":"Package renamed from 'rollup-plugin-memfs' to 'rollup-plugin-memfs' (no change, but major version bump to 4 changes API).","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use memfs v4 and its Promise-based API: import createFs from 'memfs/lib/promises'.","message":"memfs v3 is deprecated; memfs v4 changes the filesystem API.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Install memfs separately: npm install memfs","message":"The plugin requires memfs as a peer dependency, but it is not listed in package.json dependencies.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set onwarn to log warnings: onwarn(warning, defaultHandler) => { console.warn(warning.message); }","message":"Rollup's onwarn option may ignore file system errors that are caught by memfs.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Switch to ESM: use import or set type:\"module\" in package.json.","cause":"Package is ESM-only; using require() instead of import.","error":"Error: Cannot find module 'rollup-plugin-memfs'"},{"fix":"Use named import: import { memfsPlugin } from 'rollup-plugin-memfs'.","cause":"Incorrect import: default import used when only named export exists.","error":"TypeError: memfsPlugin is not a function"},{"fix":"Add the file to the volume: vol.fromJSON({'/index.js': 'content'}).","cause":"The file path does not exist in the memfs volume.","error":"Error: ENOENT: no such file or directory, open '/index.js'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}