Registry / devops / rollup-plugin-process-env

rollup-plugin-process-env

JSON →
library1.0.7jsnpmunverified

A Rollup plugin that injects `process.env` variables into the build. Current stable version is 1.0.7 (released 2023). It supports prefix-based filtering, custom filter functions, or direct object mapping. Unlike @rollup/plugin-replace or @rollup/plugin-inject, this plugin specifically handles `process.env` references and offers built-in dotenv integration guidance. Ships TypeScript types. Release cadence is low; updates are infrequent. Key differentiators: simple API, no additional configuration for common use cases, and explicit support for dotenv/dotenv-expand.

npm install rollup-plugin-process-env
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-PROC
R
rollup-plugin-process-env
devopsjavascriptv1.0.7
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.

default
import env from 'rollup-plugin-process-env'
const env = require('rollup-plugin-process-env');
ESM-only; CommonJS require not supported by the plugin's packaging.
env as function
import env from 'rollup-plugin-process-env'; plugins: [ env('MY_PREFIX_') ]
import { env } from 'rollup-plugin-process-env';
The plugin exports a default function; named import { env } will be undefined.
type definitions
import type { Options } from 'rollup-plugin-process-env'
import { Options } from 'rollup-plugin-process-env';
TypeScript types are included; but Options is not a runtime export, it's a type.

Basic Rollup configuration that uses the plugin to inject two custom environment variables into the bundle.

import env from 'rollup-plugin-process-env'; export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'es' }, plugins: [ env({ MY_VAR: 'hello', ANOTHER: 'world' }) ] };
Debug
Known issues
gotchaThe plugin only replaces `process.env` references that appear exactly as `process.env.VAR_NAME`. Dynamic accesses like `process.env['VAR_NAME']` or `process.env[varName]` are NOT replaced.
fix
Use only dot notation with static property names, or use a different plugin (e.g., @rollup/plugin-replace) for dynamic patterns.
affects: >=1.0.0
gotchaWhen using dotenv, you must manually call dotenv expansion before importing the plugin; the plugin itself does not load .env files.
fix
Add `require('dotenv-expand').expand(require('dotenv').config())` at the top of your config file.
affects: >=1.0.0
deprecatedThe plugin does not handle `process.env` reassignment (e.g., `const env = process.env; env.NODE_ENV`). Only direct `process.env.X` references are replaced.
fix
Always use `process.env.X` directly in your code.
affects: >=1.0.0
breakingVersion 1.0.0 switched to ESM-only distribution. If using CommonJS require, the import fails.
fix
Use `import env from 'rollup-plugin-process-env'` in an ESM context (enable ESM in your package.json or use .mjs extension).
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/rollup-plugin-process-env/dist/index.mjs from /path/to/rollup.config.js not supported.
Trying to require() the plugin in a CommonJS context; plugin is ESM-only since v1.0.0.
fix
Rename rollup.config.js to rollup.config.mjs or set "type": "module" in package.json, then use import syntax.
TypeError: (0 , rollup_plugin_process_env.default) is not a function
Using named import { env } instead of default import.
fix
Use `import env from 'rollup-plugin-process-env'` without curly braces.
Uncaught ReferenceError: process is not defined
The plugin runs at build time; runtime references to `process` outside of replaced variables remain if the environment does not define `process`.
fix
Ensure your target environment supports `process`, or use a polyfill like @rollup/plugin-inject to define `process` globally.
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
15
OpenAI (training)
1
Resources
rollup-plugin-process-env — npm install rollup-plugin-process-env · libregistry