{"id":28457,"library":"webpack-env-loader-plugin","title":"webpack-env-loader-plugin","description":"A webpack plugin that extends DefinePlugin to load environment-specific configuration from files like config.{env}.json. It merges defaults (config.default.json) with environment-specific files and optionally loads local overrides and process.env values. The plugin exposes config under a global namespace (default: __CONFIG__) that webpack replaces at build time. It supports JSON and YAML config files. Version 1.0.0 is the latest stable release. Unlike dotenv or env-cmd, this plugin integrates directly into webpack's compilation process and can conditionally set React production mode via reactEnv option.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install webpack-env-loader-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-env-loader-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-env-loader-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package does not ship ES modules; use CommonJS require in webpack.config.js","wrong":"import EnvLoaderPlugin from 'webpack-env-loader-plugin';","symbol":"EnvLoaderPlugin","correct":"const EnvLoaderPlugin = require('webpack-env-loader-plugin');"},{"note":"If using TypeScript or ESM webpack config, may need to set esModuleInterop or use default import, but package has no type definitions.","wrong":null,"symbol":"EnvLoaderPlugin","correct":"import EnvLoaderPlugin from 'webpack-env-loader-plugin';"},{"note":"No TypeScript types provided; type import will fail.","wrong":"import type { EnvLoaderPlugin } from 'webpack-env-loader-plugin';","symbol":"EnvLoaderPlugin (type import)","correct":"const EnvLoaderPlugin = require('webpack-env-loader-plugin');"}],"quickstart":{"code":"const EnvLoaderPlugin = require('webpack-env-loader-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: { filename: 'bundle.js' },\n  plugins: [\n    new EnvLoaderPlugin({\n      env: process.env.NODE_ENV || 'development',\n      reactEnv: true,\n      namespace: '__CONFIG__',\n      filePattern: 'config.{env}.json',\n      path: __dirname,\n      loadDefault: true,\n      loadLocalOverride: null,\n      log: true\n    })\n  ]\n};\n// Then run: NODE_ENV=production webpack\n// In source code: if (__CONFIG__.API_URL) { fetch(__CONFIG__.API_URL); }","lang":"javascript","description":"Basic webpack configuration using EnvLoaderPlugin with NODE_ENV, React production mode, and custom config file pattern."},"warnings":[{"fix":"Ensure config values are strings or wrap them in JSON.stringify in the config file or in the plugin options using a custom transformer.","message":"Config values are replaced at compile time as string literals via DefinePlugin. If a value is a string, it will be inlined with quotes, but numbers, booleans, or objects may not be handled correctly without explicit JSON.stringify.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Do not rely on process.env overrides via this plugin; manually merge environment variables in your config file or use dotenv separately.","message":"The loadFromProcessEnv option is documented but not yet implemented. Attempting to use it will be ignored.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Refer to the changelog for migration steps; likely update option names to match current docs.","message":"Prior to version 1.0.0, the plugin may have used a different API or default namespace. Check your configuration if upgrading from an older version.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Instead of reactEnv: true, rely on NODE_ENV=production and webpack's mode setting to enable React production mode.","message":"The reactEnv option is deprecated in modern React (v17+). Setting it to true adds __DEV__ and process.env.NODE_ENV to global config, which may conflict with newer React's built-in production mode detection via NODE_ENV.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Use require('webpack-env-loader-plugin') in webpack.config.js","cause":"Using an ES import (import EnvLoaderPlugin from ...) in a CommonJS webpack config, or missing require()","error":"ERROR in Plugin could not be loaded: EnvLoaderPlugin is not a constructor"},{"fix":"Ensure webpack.config.js includes the EnvLoaderPlugin in plugins array and that your source file is an entry point or module","cause":"Webpack is not running with the plugin, or the source file is not processed by webpack (e.g., outside of bundle)","error":"ReferenceError: __CONFIG__ is not defined"},{"fix":"Create config.default.json in the path specified (default: process.cwd()) or set loadDefault: false","cause":"Default config file is missing or path option is incorrect","error":"Module not found: Error: Can't resolve 'config.default.json'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}