{"id":21989,"library":"rollup-plugin-dotenv","title":"rollup-plugin-dotenv","description":"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.","status":"active","version":"0.5.1","language":"javascript","source_language":"en","source_url":"https://github.com/Andarist/rollup-plugin-dotenv","tags":["javascript","rollup","dotenv","typescript"],"install":[{"cmd":"npm install rollup-plugin-dotenv","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-dotenv","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-dotenv","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for string replacement of process.env references.","package":"@rollup/plugin-replace","optional":false},{"reason":"Used to load .env files.","package":"dotenv","optional":false}],"imports":[{"note":"The default export is a function that returns the Rollup plugin. In CJS, use require to get the default, but ESM style is preferred.","wrong":"const dotenv = require('rollup-plugin-dotenv')","symbol":"default","correct":"import dotenv from 'rollup-plugin-dotenv'"},{"note":"Destructuring the require is incorrect as the module exports a single function as default.","wrong":"const { dotenv } = require('rollup-plugin-dotenv')","symbol":"dotenv","correct":"const dotenv = require('rollup-plugin-dotenv')"},{"note":"TypeScript types are available; you can import types for options.","wrong":null,"symbol":"Types","correct":"import type { RollupPluginDotenvOptions } from 'rollup-plugin-dotenv'"}],"quickstart":{"code":"// rollup.config.js\nimport dotenv from 'rollup-plugin-dotenv';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'esm'\n  },\n  plugins: [\n    dotenv({\n      cwd: '.',\n      envKey: 'NODE_ENV'\n    })\n  ]\n};","lang":"javascript","description":"Basic Rollup configuration using rollup-plugin-dotenv to replace process.env references with values from .env files."},"warnings":[{"fix":"Use static property access for env vars that should be replaced at build time.","message":"Dynamic access like `process.env[VAR]` will NOT be replaced. Only static references like `process.env.FOO` are handled.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Avoid using process.env.VAR names that might conflict with other strings in your code.","message":"The plugin uses @rollup/plugin-replace, which can have unexpected side effects if the same variable name appears in other contexts.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade Rollup to >= 1.20.0 or use older version of the plugin.","message":"Version 0.5.0 dropped support for Rollup < 1.20.0.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Use runtime dotenv for development if needed, or configure Rollup to replace only in production builds.","message":"The plugin only replaces in bundled output, not in source code. process.env references remain in source during development.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Ensure you call dotenv() without arguments or with valid options. If you pass custom options, they must include valid keys.","cause":"Missing or misconfigured options passed to the plugin. The plugin expects certain internal configuration.","error":"Error: [plugin-replace] You must specify a values object or a delimiters array."},{"fix":"Use import dotenv from 'rollup-plugin-dotenv' or const dotenv = require('rollup-plugin-dotenv').","cause":"Using incorrect import style, e.g., importing { dotenv } instead of default.","error":"TypeError: dotenv is not a function"},{"fix":"Ensure .env files exist in the current working directory or set the cwd option to the correct directory.","cause":"The .env file is not found at the expected location.","error":"Error: Could not resolve './.env'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}