rollup-plugin-hypothetical

raw JSON →
2.1.1 verified Mon Apr 27 auth: no javascript

A Rollup plugin that provides a virtual file system for testing other plugins without actual disk I/O. Version 2.1.1 is stable, with infrequent releases. Unlike other virtual file plugins, it supports sourcemaps via { code, map } objects, configurable fallthrough behavior, implied extensions, and custom CWD. Ideal for unit testing Rollup plugins that depend on file resolution.

error Error: Could not resolve './nonexistent.js' from 'main.js'
cause File not defined in options.files and allowFallthrough is false.
fix
Add the file to options.files or set allowFallthrough: true if you want Rollup to resolve it from disk.
error Error: Cannot find module 'rollup-plugin-hypothetical'
cause Package not installed.
fix
Run npm install --save-dev rollup-plugin-hypothetical.
error TypeError: hypothetical is not a function
cause Incorrect import: using named import instead of default.
fix
Use import hypothetical from 'rollup-plugin-hypothetical' (default import).
gotcha Options.files keys are resolved relative to process.cwd() by default, not rollup's input file directory.
fix Use absolute paths or set options.cwd explicitly to match your project root.
deprecated Using options.files with a plain object may cause issues with keys like __proto__.
fix Use options.filesMap (Map) instead to avoid prototype pollution.
gotcha External imports fall through by default (allowExternalFallthrough=true), which may cause silent errors if the import is not resolved.
fix Set allowExternalFallthrough: false to force explicit definitions for external imports.
breaking options.impliedExtensions default changed from ['.js'] to ['.js', '/'] in v2.0.0.
fix If relying on the old default, explicitly set impliedExtensions: ['.js'].
npm install rollup-plugin-hypothetical
yarn add rollup-plugin-hypothetical
pnpm add rollup-plugin-hypothetical

Creates a Rollup config with hypothetical files for a simple greeting module.

// rollup.config.js
import hypothetical from 'rollup-plugin-hypothetical';

export default {
  input: 'main.js',
  plugins: [
    hypothetical({
      files: {
        'main.js': `
          import { greet } from './greet.js';
          console.log(greet('World'));
        `,
        'greet.js': `
          export function greet(name) {
            return 'Hello, ' + name + '!';
          }
        `
      }
    })
  ],
  output: { file: 'out.js', format: 'esm' }
};

// Then run: npx rollup -c