{"id":20798,"library":"webpack-mode","title":"webpack-mode","description":"Get the current mode (production/development) of a Webpack 4 build. Version 1.1.0 is the latest stable release. This tiny utility checks the `--mode` CLI flag or `NODE_ENV` environment variable and exposes `isProduction`, `isDevelopment`, and a string-comparable object. Works only with Webpack 4 — it will silently return wrong results on Webpack 5. No dependencies, no TypeScript types.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/mckomo/webpack-mode","tags":["javascript","webpack","mode","environment"],"install":[{"cmd":"npm install webpack-mode","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-mode","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-mode","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export, not default. CJS only — package does not ship ESM.","wrong":"const { isProduction } = require('webpack-mode').default","symbol":"isProduction","correct":"const { isProduction } = require('webpack-mode')"},{"note":"Same as isProduction. The require returns an object with named properties.","wrong":"const isDevelopment = require('webpack-mode').isDevelopment","symbol":"isDevelopment","correct":"const { isDevelopment } = require('webpack-mode')"},{"note":"The module exports an object that is also string-comparable (via toString). Not a string, so strict equality fails.","wrong":"const mode = require('webpack-mode').default","symbol":"default export (the mode value)","correct":"const mode = require('webpack-mode')"}],"quickstart":{"code":"const { isProduction, isDevelopment } = require('webpack-mode');\n\nif (isProduction) {\n  console.log('Building for production');\n} else if (isDevelopment) {\n  console.log('Building for development');\n} else {\n  console.log('Mode not set');\n}\n\n// Or get the mode as a string-comparable object:\nconst mode = require('webpack-mode');\nif (`${mode}` === 'production') {\n  console.log('Mode is production');\n}","lang":"javascript","description":"Checks if Webpack is running in production or development mode using named exports, and shows object string comparison."},"warnings":[{"fix":"Use Webpack's built-in mode detection or upgrade to a Webpack 5-compatible library.","message":"webpack-mode works only with Webpack 4. On Webpack 5, the mode detection will likely fail or return incorrect results.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use template literals (`${mode}`) or the .toString() method, or use the named exports isProduction/isDevelopment.","message":"The default export is not a string; strict equality (===) with a string will always be false.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Create a .d.ts file: declare module 'webpack-mode' { export const isProduction: boolean; export const isDevelopment: boolean; const mode: { toString(): string }; export default mode; }","message":"No TypeScript type definitions available; using with TypeScript will require manual declare module.","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":"Run 'npm install --save-dev webpack-mode' or 'yarn add --dev webpack-mode'.","cause":"Package not installed or installed as a devDependency but used in production code.","error":"Cannot find module 'webpack-mode'"},{"fix":"Use `if (`${webpackMode}` === 'production')` instead of `if (webpackMode === 'production')`.","cause":"Using strict equality (===) on the default export.","error":"TypeError: webpackMode is not a string"},{"fix":"Add a custom type declaration file (.d.ts) as shown in the warnings.","cause":"TypeScript cannot find typings for the package.","error":"Property 'isProduction' does not exist on type 'typeof import(\"webpack-mode\")'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}