{"id":20750,"library":"webpack-dotenv-plugin","title":"Dotenv Plugin for Webpack","description":"A webpack plugin that uses dotenv-safe to load environment variables from a .env file and make them available as process.env replacements during the webpack build. Version 2.1.0 requires webpack >=1.13.0 as a peer dependency. It supports custom paths for .env and sample files, respects externally set environment variables, and fixed a deprecation warning for webpack 4.x. Unlike other dotenv-webpack plugins, this one uses dotenv-safe to ensure required variables are defined. Release cadence is irregular; last update was in 2018.","status":"maintenance","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/nwinch/webpack-dotenv-plugin","tags":["javascript","webpack","dotenv","dot","env","environment","variables","plugin"],"install":[{"cmd":"npm install webpack-dotenv-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-dotenv-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-dotenv-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; required to function as a webpack plugin.","package":"webpack","optional":false}],"imports":[{"note":"Package does not ship ESM; CommonJS require is required.","wrong":"import DotenvPlugin from 'webpack-dotenv-plugin';","symbol":"DotenvPlugin","correct":"const DotenvPlugin = require('webpack-dotenv-plugin');"},{"note":"This is the default export; no named exports exist.","symbol":"DotenvPlugin","correct":"const DotenvPlugin = require('webpack-dotenv-plugin');"},{"note":"If using ES module syntax with bundler, default import works, but named import is incorrect.","wrong":"const { DotenvPlugin } = require('webpack-dotenv-plugin');","symbol":"DotenvPlugin","correct":"import DotenvPlugin from 'webpack-dotenv-plugin';"}],"quickstart":{"code":"// webpack.config.js\nconst DotenvPlugin = require('webpack-dotenv-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    filename: 'bundle.js',\n    path: __dirname + '/dist'\n  },\n  plugins: [\n    new DotenvPlugin({\n      sample: './.env.sample',\n      path: './.env',\n      allowEmptyValues: true\n    })\n  ]\n};","lang":"javascript","description":"Configures webpack to load environment variables from .env file using dotenv-safe, with sample file and allowEmptyValues option."},"warnings":[{"fix":"Rename .env.default to .env.sample or update the sample option to point to your existing file.","message":"In v2.0.0, the sample file path changed from '.env.default' to '.env.sample'. If you have a .env.default file, it will not be found.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Install webpack: npm install --save-dev webpack","message":"In v2.0.0, webpack was moved to a peer dependency. You must install webpack separately.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Review dotenv-safe 5.0.1 release notes for any deprecated options.","message":"v2.1.0 uses dotenv-safe 5.0.1, which may have deprecations. Check dotenv-safe changelog.","severity":"deprecated","affected_versions":"2.1.0"},{"fix":"Parse values in your code as needed (e.g., Boolean(process.env.DEBUG)).","message":"The plugin stringifies environment variables, so all values become strings. Boolean or numeric values in .env will be converted to strings.","severity":"gotcha","affected_versions":"*"},{"fix":"Be aware of the override behavior; unset external variables if you want .env to take precedence.","message":"Externally set environment variables override those in .env. This may cause unexpected behavior if your system has conflicting variables.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install --save-dev webpack-dotenv-plugin","cause":"Package not installed or installed as devDependency but not in node_modules.","error":"Module not found: Error: Can't resolve 'webpack-dotenv-plugin'"},{"fix":"Ensure webpack is installed: npm install --save-dev webpack","cause":"dotenv-safe is a transitive dependency, but may not be resolved if peer deps are missing.","error":"Error: Cannot find module 'dotenv-safe'"},{"fix":"Upgrade to webpack-dotenv-plugin >=2.1.0","cause":"Using plugin with webpack 4+; older plugin versions had this warning.","error":"DeprecationWarning: Tapable.apply is deprecated","affected_versions":"<2.1.0"},{"fix":"Create a .env.sample file or specify sample option to point to your existing file.","cause":"The sample file path default was changed in v2.0.0 from .env.default to .env.sample.","error":"no such file or directory, open '.env.sample'","affected_versions":">=2.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}