{"id":20238,"library":"node-env-webpack-plugin","title":"Node Env Webpack Plugin","description":"Simplifies NODE_ENV handling in webpack builds. Current stable version 2.0.0 (2024), requires Node.js >=18 and is pure ESM. Sets process.env.NODE_ENV automatically: defaults to 'development' at import time if undefined, or 'production' when webpack runs with -p. Provides convenience boolean getters (isProduction, isDevelopment, isTest) to avoid typos, and a devtool helper that selects source-map in production and cheap-module-source-map in development. Replaces manual NODE_ENV checks and webpack.EnvironmentPlugin setup with a single plugin.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/sindresorhus/node-env-webpack-plugin","tags":["javascript","webpack-plugin","webpack","node","node-env","env","environment","development","production"],"install":[{"cmd":"npm install node-env-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add node-env-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-env-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"v2.0.0 is pure ESM; cannot use require().","wrong":"const NodeEnvPlugin = require('node-env-webpack-plugin')","symbol":"NodeEnvPlugin","correct":"import NodeEnvPlugin from 'node-env-webpack-plugin'"},{"note":"isProduction is a static property of the default export, not a named export.","wrong":"import { isProduction } from 'node-env-webpack-plugin'","symbol":"NodeEnvPlugin.isProduction","correct":"import NodeEnvPlugin from 'node-env-webpack-plugin'; NodeEnvPlugin.isProduction"},{"note":"devtool is a static property; destructuring only works with ESM named exports (not available here).","wrong":"const { devtool } = require('node-env-webpack-plugin')","symbol":"NodeEnvPlugin.devtool","correct":"import NodeEnvPlugin from 'node-env-webpack-plugin'; NodeEnvPlugin.devtool"}],"quickstart":{"code":"// webpack.config.js\nimport NodeEnvPlugin from 'node-env-webpack-plugin';\n\nexport default {\n  entry: './src/index.js',\n  output: {\n    filename: 'bundle.js'\n  },\n  devtool: NodeEnvPlugin.devtool,\n  plugins: [\n    new NodeEnvPlugin()\n  ]\n};","lang":"javascript","description":"Minimal webpack config using NodeEnvPlugin to auto-set NODE_ENV and configure devtool based on environment."},"warnings":[{"fix":"Use import instead of require, and ensure Node.js >=18.","message":"v2.0.0 dropped support for Node.js <18 and is now pure ESM. CommonJS require() will throw.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade to webpack 5.","message":"v2.0.0 stopped supporting webpack <5. The plugin only works with webpack 5+.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Set NODE_ENV before importing the plugin or use explicit webpack mode.","message":"NODE_ENV is set at import time, not when the plugin is instantiated. If you import the plugin but then change process.env.NODE_ENV before webpack processes the config, the plugin's static properties are based on the initial value.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need to force a specific NODE_ENV, set it explicitly in the environment.","message":"The plugin does not override NODE_ENV if it's already set. It only sets it when undefined at import time.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Switch to import syntax (import NodeEnvPlugin from 'node-env-webpack-plugin') or use dynamic import() if needed.","cause":"Using CommonJS require() on an ESM-only package.","error":"require() of ES Module ... from ... not supported"},{"fix":"Run 'npm install node-env-webpack-plugin' and ensure Node.js >=18.","cause":"The package is not installed or Node.js version is <18 (v2 requires Node.js 18).","error":"Cannot find module 'node-env-webpack-plugin'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}