{"id":20818,"library":"webpack-require-weak","title":"webpack-require-weak","description":"Utility for using webpack's resolveWeak to conditionally require modules in webpack bundles. Version 1.0.1, no active release cadence. Key differentiator: enables optional module loading without webpack bundling the module, useful for universal modules that work both in webpack and Node.js. Typically used alongside `is-webpack-bundle`.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/thejameskyle/universal-webpack-require","tags":["javascript"],"install":[{"cmd":"npm install webpack-require-weak","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-require-weak","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-require-weak","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used to check if running inside webpack bundle before using resolveWeak","package":"is-webpack-bundle","optional":true}],"imports":[{"note":"ESM import may fail if package doesn't have proper ESM exports; use CJS require.","wrong":"import webpackRequireWeak from 'webpack-require-weak'","symbol":"webpackRequireWeak","correct":"const webpackRequireWeak = require('webpack-require-weak')"},{"note":"If using ESM, ensure bundler resolves default export.","symbol":"webpackRequireWeak","correct":"import webpackRequireWeak from 'webpack-require-weak'"},{"note":"In some transpilation setups, require returns an object with default property.","wrong":"const webpackRequireWeak = require('webpack-require-weak')","symbol":"webpackRequireWeak","correct":"const webpackRequireWeak = require('webpack-require-weak').default"}],"quickstart":{"code":"const isWebpackBundle = require('is-webpack-bundle');\nconst webpackRequireWeak = require('webpack-require-weak');\n\nlet myModule;\nif (isWebpackBundle) {\n  myModule = webpackRequireWeak(require.resolveWeak('./path/to/module'));\n} else {\n  myModule = require('./path/to/module');\n}\n\n// Ensure webpack doesn't bundle the module conditionally\nif (myModule) {\n  myModule.doSomething();\n}","lang":"javascript","description":"Shows conditional require using webpack's resolveWeak to avoid bundling the module in webpack, falling back to normal require in Node."},"warnings":[{"fix":"Always check isWebpackBundle before calling webpackRequireWeak.","message":"webpack-require-weak requires webpack's resolveWeak which is only available inside a webpack bundle. Using it outside webpack will throw.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always check for null or undefined before using the returned module.","message":"The return value from webpackRequireWeak may be null if the module cannot be resolved at runtime.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Declare module in a .d.ts file: declare module 'webpack-require-weak';","message":"The package has no TypeScript types. Using with TypeScript may require custom type definitions.","severity":"gotcha","affected_versions":">=0.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 webpack-require-weak","cause":"Package not installed or not in node_modules.","error":"Error: Cannot find module 'webpack-require-weak'"},{"fix":"Use: const webpackRequireWeak = require('webpack-require-weak').default;","cause":"Default import incorrect in certain environments.","error":"TypeError: webpackRequireWeak is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}