rollup-plugin-ephemeral
raw JSON → 0.0.1 verified Mon Apr 27 auth: no javascript
A Rollup plugin for creating virtual modules that behave like real files, useful for testing or generating modules on-the-fly. Version 0.0.1 is the initial unstable release. Different from @rollup/plugin-virtual in that ephemeral modules are treated as real file modules by Rollup, affecting resolution and caching behavior. This package ships TypeScript types and supports ESM only.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/rollup-plugin-ephemeral/index.js not supported. ↓
cause The package is ESM-only, but the project is using CommonJS require() to load the plugin.
fix
Switch to dynamic import: const ephemeral = await import('rollup-plugin-ephemeral'); or configure your project as ESM.
error TypeError: ephemeral is not a function ↓
cause Importing the default export incorrectly, e.g., using named import where only default export exists.
fix
Use: import ephemeral from 'rollup-plugin-ephemeral'; Do not use named import: import { ephemeral } from 'rollup-plugin-ephemeral';
Warnings
breaking ESM-only: rollup-plugin-ephemeral uses native ES modules. Using require() will throw MODULE_NOT_FOUND. ↓
fix Use import syntax and ensure your project is configured for ESM (e.g., type: module in package.json).
gotcha Virtual modules created by this plugin are treated as real files by Rollup's resolveId hook, which may affect caching and watch mode behavior differently than @rollup/plugin-virtual. ↓
fix If you need standard virtual module behavior, use @rollup/plugin-virtual instead.
gotcha The plugin does not support side effects via a separate options object; all arguments are positional. Pass only id and code. ↓
fix Call ephemeral('id', 'code') with exactly two string arguments.
Install
npm install rollup-plugin-ephemeral yarn add rollup-plugin-ephemeral pnpm add rollup-plugin-ephemeral Imports
- ephemeral wrong
const ephemeral = require('rollup-plugin-ephemeral')correctimport ephemeral from 'rollup-plugin-ephemeral' - ephemeral (named export) wrong
import { default as ephem } from 'rollup-plugin-ephemeral'correctimport { ephemeral } from 'rollup-plugin-ephemeral' - ephemeral (type import) wrong
import { RollupPluginEphemeralOptions } from 'rollup-plugin-ephemeral'correctimport type { RollupPluginEphemeralOptions } from 'rollup-plugin-ephemeral'
Quickstart
import ephemeral from 'rollup-plugin-ephemeral';
import { rollup } from 'rollup';
const bundle = await rollup({
input: 'entry.js',
plugins: [
ephemeral('entry.js', 'export const answer = 42;'),
],
});
const { output } = await bundle.generate({ format: 'es' });
console.log(output[0].code);