Registry / devops / webpack-mode

webpack-mode

JSON →
library1.1.0jsnpmunverified

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.

npm install webpack-mode
INSTALL
IMPORT
SIG · WEBPACK-MODE
W
webpack-mode
devopsjavascriptv1.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

isProduction
✓ const { isProduction } = require('webpack-mode')
✗ const { isProduction } = require('webpack-mode').default
Named export, not default. CJS only — package does not ship ESM.
isDevelopment
✓ const { isDevelopment } = require('webpack-mode')
✗ const isDevelopment = require('webpack-mode').isDevelopment
Same as isProduction. The require returns an object with named properties.
default export (the mode value)
✓ const mode = require('webpack-mode')
✗ const mode = require('webpack-mode').default
The module exports an object that is also string-comparable (via toString). Not a string, so strict equality fails.

Checks if Webpack is running in production or development mode using named exports, and shows object string comparison.

const { isProduction, isDevelopment } = require('webpack-mode'); if (isProduction) { console.log('Building for production'); } else if (isDevelopment) { console.log('Building for development'); } else { console.log('Mode not set'); } // Or get the mode as a string-comparable object: const mode = require('webpack-mode'); if (`${mode}` === 'production') { console.log('Mode is production'); }
Debug
Known issues
gotchawebpack-mode works only with Webpack 4. On Webpack 5, the mode detection will likely fail or return incorrect results.
fix
Use Webpack's built-in mode detection or upgrade to a Webpack 5-compatible library.
affects: >=1.0.0
gotchaThe default export is not a string; strict equality (===) with a string will always be false.
fix
Use template literals (`${mode}`) or the .toString() method, or use the named exports isProduction/isDevelopment.
affects: >=1.0.0
gotchaNo TypeScript type definitions available; using with TypeScript will require manual declare module.
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; }
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'webpack-mode'
Package not installed or installed as a devDependency but used in production code.
fix
Run 'npm install --save-dev webpack-mode' or 'yarn add --dev webpack-mode'.
TypeError: webpackMode is not a string
Using strict equality (===) on the default export.
fix
Use `if (`${webpackMode}` === 'production')` instead of `if (webpackMode === 'production')`.
Property 'isProduction' does not exist on type 'typeof import("webpack-mode")'
TypeScript cannot find typings for the package.
fix
Add a custom type declaration file (.d.ts) as shown in the warnings.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Resources
webpack-mode — npm install webpack-mode · libregistry