Registry / devops / rollup-plugin-codegen

rollup-plugin-codegen

JSON →
library2.1.0jsnpmunverified

A Rollup plugin for generating source code modules at bundle time. Current stable version is 2.1.0, released with fixes and support for Bun and Parcel loaders. This plugin allows dynamic generation of modules based on configuration, useful for injecting environment variables, version info, or computed code. Key differentiator: it integrates directly into Rollup's build process, avoiding separate pre-build steps. Ships TypeScript types, supports ESM and CJS outputs, requires Node >=16.0. Alternative to virtual modules or manual file writes.

npm install rollup-plugin-codegen
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-CODE
R
rollup-plugin-codegen
devopsjavascriptv2.1.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.

codegen
import { codegen } from 'rollup-plugin-codegen'
import codegen from 'rollup-plugin-codegen'
ESM-only since v2; named export, not default. TypeScript types included.
Plugin
import type { Plugin } from 'rollup-plugin-codegen'
const { Plugin } = require('rollup-plugin-codegen')
Type export for TypeScript users; not available in CJS.
CodegenOptions
import type { CodegenOptions } from 'rollup-plugin-codegen'
Use this type for the options object parameter.

Shows how to configure codegen plugin to generate a module with environment variable.

import { codegen } from 'rollup-plugin-codegen'; import { defineConfig } from 'rollup'; export default defineConfig({ input: 'src/index.js', plugins: [ codegen({ modules: [ { id: 'src/env', code: `export const NODE_ENV = ${JSON.stringify(process.env.NODE_ENV ?? 'development')};` } ] }) ], output: { dir: 'dist', format: 'esm' } });
Debug
Known issues
breakingVersion 2.0.0 changed from default export to named export
fix
Use `import { codegen } from 'rollup-plugin-codegen'` instead of `import codegen from 'rollup-plugin-codegen'`
affects: >=2.0.0
breakingNode version requirement changed to >=16.0
fix
Upgrade Node.js to version 16 or later.
affects: >=2.0.0
gotchaGenerated module IDs must be relative and unique; duplicate IDs cause errors
fix
Ensure each module id is a unique relative path string (e.g., 'src/generated/env').
affects: all
Errors
Common errors & fixes
Error: The plugin 'codegen' does not export a default export.
Using default import instead of named import in ESM environment.
fix
Change `import codegen from 'rollup-plugin-codegen'` to `import { codegen } from 'rollup-plugin-codegen'`
Error: Cannot find module 'rollup-plugin-codegen'
Package not installed or not in node_modules.
fix
Run `npm install rollup-plugin-codegen` or `yarn add rollup-plugin-codegen`.
Error: The generated module 'src/env' could not be resolved.
The module ID path does not match Rollup's resolution or file system.
fix
Ensure the module id is a relative path that does not conflict with existing files. Use a path like 'src/generated/env' that doesn't exist on disk.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
rolluprequiredPeer dependency; requires Rollup version 2 or higher.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
rollup-plugin-codegen — npm install rollup-plugin-codegen · libregistry