Registry / is-webpack-bundle

is-webpack-bundle

JSON →
library1.0.0jsnpmunverified

A micro-package (v1.0.0, no active releases since 2019) that detects at runtime whether the current module was bundled by webpack. It works by checking for the presence of a `__webpack_require__` function in the global scope. This is a simple, single-purpose utility with no dependencies. For similar detection in other bundlers (e.g., Rollup, Parcel), alternative approaches are needed. The package is published as a CommonJS module only, with no TypeScript type definitions.

npm install is-webpack-bundle
INSTALL
IMPORT
SIG · IS-WEBPACK-BUNDLE
I
is-webpack-bundle
javascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default
const isWebpackBundle = require('is-webpack-bundle');
import isWebpackBundle from 'is-webpack-bundle';
Package is CommonJS-only; ESM import will fail in Node or bundlers expecting ESM.
default (ESM)
import isWebpackBundle from 'is-webpack-bundle';
const isWebpackBundle = require('is-webpack-bundle');
If your project is ESM, this import works in Node 12+ with `--experimental-require` or with bundlers like webpack, but the package itself is CJS. Prefer require for clarity.
default (TypeScript)
// @ts-ignore or declare module const isWebpackBundle = require('is-webpack-bundle');
import isWebpackBundle from 'is-webpack-bundle';
No type definitions exist. Use require with a type assertion or disable strict module checks.

Shows how to check if code is webpack-bundled and conditionally handle logic.

const isWebpackBundle = require('is-webpack-bundle'); if (isWebpackBundle) { console.log('Running inside a webpack bundle'); } else { console.log('Not bundled by webpack'); } // Example usage: conditionally handle module exports const myModule = isWebpackBundle ? { bundled: true } : { bundled: false }; module.exports = myModule;
Debug
Known issues
gotchaThe check relies on a global `__webpack_require__` which may be absent in certain webpack configurations (e.g., output.libraryTarget: 'var') or minified bundles.
fix
Verify the check works in your specific webpack setup; consider alternative detection methods.
affects: >=1.0.0
gotchaIf the code is bundled with another bundler (e.g., Rollup, Parcel), the check will incorrectly return false even if inside a bundle.
fix
Use a bundler-agnostic detection library or check for other globals.
affects: >=1.0.0
gotchaThe module is CommonJS-only; importing via ESM may cause issues in strict ESM environments.
fix
Use require() or configure your bundler to handle CJS interop.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'is-webpack-bundle'
Package not installed or typo in package name.
fix
Run npm install is-webpack-bundle
Uncaught ReferenceError: __webpack_require__ is not defined
The package's global check fails because __webpack_require__ is not exposed (e.g., in Node.js environment without webpack).
fix
This error should not happen because the package catches the ReferenceError internally; if it does, ensure you are not modifying global scope or using eval.
SyntaxError: Cannot use import statement outside a module
Trying to ESM-import the package without proper module configuration.
fix
Use require() or set "type": "module" in package.json and ensure the import path is valid.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
is-webpack-bundle — npm install is-webpack-bundle · libregistry