Registry / http-networking / rollup-plugin-dotenv

rollup-plugin-dotenv

JSON →
library0.5.1jsnpmunverified

Rollup plugin that loads .env files and replaces process.env references at build time. Current stable version is 0.5.1. Released irregularly, with the last release in 2023. It integrates with @rollup/plugin-replace under the hood for environment variable substitution. Supports multiple .env files with environment-specific overrides (e.g., .env.production.local). Unlike runtime dotenv packages, this plugin performs compile-time replacement, which can improve performance and security. No browser or client-side usage. Only supports CommonJS requires? Note: This plugin does not support dynamic access like process.env[VAR]. Shipping TypeScript types.

npm install rollup-plugin-dotenv
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-DOTE
R
rollup-plugin-dotenv
http-networkingjavascriptv0.5.1
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 dotenv from 'rollup-plugin-dotenv'
const dotenv = require('rollup-plugin-dotenv')
The default export is a function that returns the Rollup plugin. In CJS, use require to get the default, but ESM style is preferred.
dotenv
const dotenv = require('rollup-plugin-dotenv')
const { dotenv } = require('rollup-plugin-dotenv')
Destructuring the require is incorrect as the module exports a single function as default.
Types
import type { RollupPluginDotenvOptions } from 'rollup-plugin-dotenv'
TypeScript types are available; you can import types for options.

Basic Rollup configuration using rollup-plugin-dotenv to replace process.env references with values from .env files.

// rollup.config.js import dotenv from 'rollup-plugin-dotenv'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'esm' }, plugins: [ dotenv({ cwd: '.', envKey: 'NODE_ENV' }) ] };
Debug
Known issues
gotchaDynamic access like `process.env[VAR]` will NOT be replaced. Only static references like `process.env.FOO` are handled.
fix
Use static property access for env vars that should be replaced at build time.
affects: >=0.0.0
gotchaThe plugin uses @rollup/plugin-replace, which can have unexpected side effects if the same variable name appears in other contexts.
fix
Avoid using process.env.VAR names that might conflict with other strings in your code.
affects: >=0.0.0
breakingVersion 0.5.0 dropped support for Rollup < 1.20.0.
fix
Upgrade Rollup to >= 1.20.0 or use older version of the plugin.
affects: >=0.5.0
gotchaThe plugin only replaces in bundled output, not in source code. process.env references remain in source during development.
fix
Use runtime dotenv for development if needed, or configure Rollup to replace only in production builds.
affects: >=0.0.0
Errors
Common errors & fixes
Error: [plugin-replace] You must specify a values object or a delimiters array.
Missing or misconfigured options passed to the plugin. The plugin expects certain internal configuration.
fix
Ensure you call dotenv() without arguments or with valid options. If you pass custom options, they must include valid keys.
TypeError: dotenv is not a function
Using incorrect import style, e.g., importing { dotenv } instead of default.
fix
Use import dotenv from 'rollup-plugin-dotenv' or const dotenv = require('rollup-plugin-dotenv').
Error: Could not resolve './.env'
The .env file is not found at the expected location.
fix
Ensure .env files exist in the current working directory or set the cwd option to the correct directory.
Upgrade
Version history
0.5.1latest on npm
Audit
Dependencies
@rollup/plugin-replacerequiredUsed internally for string replacement of process.env references.
dotenvrequiredUsed to load .env files.
Agent activity
29 hits · last 30 days
node
24
OpenAI (training)
3
Resources
rollup-plugin-dotenv — npm install rollup-plugin-dotenv · libregistry