{"id":22184,"library":"rollup-plugin-process-env","title":"rollup-plugin-process-env","description":"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.","status":"active","version":"1.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/d8corp/rollup-plugin-process-env","tags":["javascript","rollup-plugin","env","front-end","typescript"],"install":[{"cmd":"npm install rollup-plugin-process-env","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-process-env","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-process-env","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; CommonJS require not supported by the plugin's packaging.","wrong":"const env = require('rollup-plugin-process-env');","symbol":"default","correct":"import env from 'rollup-plugin-process-env'"},{"note":"The plugin exports a default function; named import { env } will be undefined.","wrong":"import { env } from 'rollup-plugin-process-env';","symbol":"env as function","correct":"import env from 'rollup-plugin-process-env';\nplugins: [ env('MY_PREFIX_') ]"},{"note":"TypeScript types are included; but Options is not a runtime export, it's a type.","wrong":"import { Options } from 'rollup-plugin-process-env';","symbol":"type definitions","correct":"import type { Options } from 'rollup-plugin-process-env'"}],"quickstart":{"code":"import env from 'rollup-plugin-process-env';\n\nexport default {\n  input: 'src/index.js',\n  output: { file: 'dist/bundle.js', format: 'es' },\n  plugins: [ env({ MY_VAR: 'hello', ANOTHER: 'world' }) ]\n};","lang":"typescript","description":"Basic Rollup configuration that uses the plugin to inject two custom environment variables into the bundle."},"warnings":[{"fix":"Use only dot notation with static property names, or use a different plugin (e.g., @rollup/plugin-replace) for dynamic patterns.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Add `require('dotenv-expand').expand(require('dotenv').config())` at the top of your config file.","message":"When using dotenv, you must manually call dotenv expansion before importing the plugin; the plugin itself does not load .env files.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `process.env.X` directly in your code.","message":"The plugin does not handle `process.env` reassignment (e.g., `const env = process.env; env.NODE_ENV`). Only direct `process.env.X` references are replaced.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use `import env from 'rollup-plugin-process-env'` in an ESM context (enable ESM in your package.json or use .mjs extension).","message":"Version 1.0.0 switched to ESM-only distribution. If using CommonJS require, the import fails.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Rename rollup.config.js to rollup.config.mjs or set \"type\": \"module\" in package.json, then use import syntax.","cause":"Trying to require() the plugin in a CommonJS context; plugin is ESM-only since v1.0.0.","error":"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."},{"fix":"Use `import env from 'rollup-plugin-process-env'` without curly braces.","cause":"Using named import { env } instead of default import.","error":"TypeError: (0 , rollup_plugin_process_env.default) is not a function"},{"fix":"Ensure your target environment supports `process`, or use a polyfill like @rollup/plugin-inject to define `process` globally.","cause":"The plugin runs at build time; runtime references to `process` outside of replaced variables remain if the environment does not define `process`.","error":"Uncaught ReferenceError: process is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}