{"id":20144,"library":"is-webpack-bundle","title":"is-webpack-bundle","description":"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.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/thejameskyle/is-webpack-bundle","tags":["javascript"],"install":[{"cmd":"npm install is-webpack-bundle","lang":"bash","label":"npm"},{"cmd":"yarn add is-webpack-bundle","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-webpack-bundle","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is CommonJS-only; ESM import will fail in Node or bundlers expecting ESM.","wrong":"import isWebpackBundle from 'is-webpack-bundle';","symbol":"default","correct":"const isWebpackBundle = require('is-webpack-bundle');"},{"note":"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.","wrong":"const isWebpackBundle = require('is-webpack-bundle');","symbol":"default (ESM)","correct":"import isWebpackBundle from 'is-webpack-bundle';"},{"note":"No type definitions exist. Use require with a type assertion or disable strict module checks.","wrong":"import isWebpackBundle from 'is-webpack-bundle';","symbol":"default (TypeScript)","correct":"// @ts-ignore or declare module\nconst isWebpackBundle = require('is-webpack-bundle');"}],"quickstart":{"code":"const isWebpackBundle = require('is-webpack-bundle');\n\nif (isWebpackBundle) {\n  console.log('Running inside a webpack bundle');\n} else {\n  console.log('Not bundled by webpack');\n}\n\n// Example usage: conditionally handle module exports\nconst myModule = isWebpackBundle\n  ? { bundled: true }\n  : { bundled: false };\n\nmodule.exports = myModule;","lang":"javascript","description":"Shows how to check if code is webpack-bundled and conditionally handle logic."},"warnings":[{"fix":"Verify the check works in your specific webpack setup; consider alternative detection methods.","message":"The check relies on a global `__webpack_require__` which may be absent in certain webpack configurations (e.g., output.libraryTarget: 'var') or minified bundles.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use a bundler-agnostic detection library or check for other globals.","message":"If the code is bundled with another bundler (e.g., Rollup, Parcel), the check will incorrectly return false even if inside a bundle.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use require() or configure your bundler to handle CJS interop.","message":"The module is CommonJS-only; importing via ESM may cause issues in strict ESM environments.","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 is-webpack-bundle","cause":"Package not installed or typo in package name.","error":"Cannot find module 'is-webpack-bundle'"},{"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.","cause":"The package's global check fails because __webpack_require__ is not exposed (e.g., in Node.js environment without webpack).","error":"Uncaught ReferenceError: __webpack_require__ is not defined"},{"fix":"Use require() or set \"type\": \"module\" in package.json and ensure the import path is valid.","cause":"Trying to ESM-import the package without proper module configuration.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}