rollup-plugin-virtual-fs
raw JSON → 4.0.1-alpha.0 verified Mon Apr 27 auth: no javascript
A Rollup plugin that provides an in-memory virtual file system, allowing you to resolve and bundle files without a physical filesystem. Current version: 4.0.1-alpha.0 (unstable, pre-release). Release cadence: irregular, alpha stage. Key differentiator: enables full Rollup bundling purely from virtual file maps, with optional fallback to real filesystem. Supports custom extension resolution. TypeScript types included.
Common errors
error Cannot find module 'rollup-plugin-virtual-fs' or its corresponding type declarations. ↓
cause Package version is alpha and may not be published correctly, or TypeScript cannot resolve types due to missing 'types' field in package.json.
fix
Ensure you have the latest alpha version installed: npm install rollup-plugin-virtual-fs@4.0.1-alpha.0. If types are missing, add a declaration file: declare module 'rollup-plugin-virtual-fs';
error TypeError: virtualFs is not a function ↓
cause Default import used when plugin exports a named function.
fix
Change import to: import { virtualFs } from 'rollup-plugin-virtual-fs';
error Error: The 'extension' option is not supported. Did you mean 'extensions'? ↓
cause Using the old singular 'extension' option (string) instead of array 'extensions'.
fix
Use 'extensions' as an array of strings, e.g., extensions: ['.js', '.ts'].
Warnings
breaking Version 4.0.0 changed the plugin export from default to named export. Import { virtualFs } instead of the old default import. ↓
fix Change 'import virtualFs from ...' to 'import { virtualFs } from ...'.
deprecated The 'extension' option is renamed to 'extensions' (plural) in v4. Using 'extension' will be silently ignored. ↓
fix Use 'extensions' (array of strings) instead of 'extension' (string).
gotcha The plugin is in alpha stage (4.0.1-alpha.0). API may change without notice. Not recommended for production. ↓
fix Pin to a specific version and test thoroughly in non-production environments.
gotcha Input must use 'file://' protocol (e.g., 'file:///index.js') to be resolved by the virtual filesystem. ↓
fix Prefix input paths with 'file://'.
gotcha The 'memoryOnly' option defaults to true. Setting it to false may expose real filesystem paths, which can be a security risk if files are controlled by untrusted sources. ↓
fix Leave memoryOnly as true (default) unless you explicitly need fallback to disk.
Install
npm install rollup-plugin-virtual-fs yarn add rollup-plugin-virtual-fs pnpm add rollup-plugin-virtual-fs Imports
- virtualFs wrong
import virtualFs from 'rollup-plugin-virtual-fs'correctimport { virtualFs } from 'rollup-plugin-virtual-fs' - VirtualFsOptions wrong
import { VirtualFsOptions } from 'rollup-plugin-virtual-fs'correctimport type { VirtualFsOptions } from 'rollup-plugin-virtual-fs' - rollup-plugin-virtual-fs (CommonJS) wrong
const virtualFs = require('rollup-plugin-virtual-fs')correctconst { virtualFs } = require('rollup-plugin-virtual-fs')
Quickstart
// rollup.config.js
import { virtualFs } from 'rollup-plugin-virtual-fs';
const files = {
'/index.js': `import foo from './foo';
export default () => console.log(foo);`,
'/foo.js': 'export default "foo"',
};
export default {
input: 'file:///index.js',
plugins: [
virtualFs({
files,
extensions: ['.ts', '.tsx', '.js', '/index.js'],
}),
],
};