Registry / devops / webpack-require-weak

webpack-require-weak

JSON →
library1.0.1jsnpmunverified

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`.

npm install webpack-require-weak
INSTALL
IMPORT
SIG · WEBPACK-REQUIRE-WE
W
webpack-require-weak
devopsjavascriptv1.0.1
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.

webpackRequireWeak
const webpackRequireWeak = require('webpack-require-weak')
import webpackRequireWeak from 'webpack-require-weak'
ESM import may fail if package doesn't have proper ESM exports; use CJS require.
webpackRequireWeak
import webpackRequireWeak from 'webpack-require-weak'
If using ESM, ensure bundler resolves default export.
webpackRequireWeak
const webpackRequireWeak = require('webpack-require-weak').default
const webpackRequireWeak = require('webpack-require-weak')
In some transpilation setups, require returns an object with default property.

Shows conditional require using webpack's resolveWeak to avoid bundling the module in webpack, falling back to normal require in Node.

const isWebpackBundle = require('is-webpack-bundle'); const webpackRequireWeak = require('webpack-require-weak'); let myModule; if (isWebpackBundle) { myModule = webpackRequireWeak(require.resolveWeak('./path/to/module')); } else { myModule = require('./path/to/module'); } // Ensure webpack doesn't bundle the module conditionally if (myModule) { myModule.doSomething(); }
Debug
Known issues
gotchawebpack-require-weak requires webpack's resolveWeak which is only available inside a webpack bundle. Using it outside webpack will throw.
fix
Always check isWebpackBundle before calling webpackRequireWeak.
affects: >=0.0.0
gotchaThe return value from webpackRequireWeak may be null if the module cannot be resolved at runtime.
fix
Always check for null or undefined before using the returned module.
affects: >=0.0.0
gotchaThe package has no TypeScript types. Using with TypeScript may require custom type definitions.
fix
Declare module in a .d.ts file: declare module 'webpack-require-weak';
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'webpack-require-weak'
Package not installed or not in node_modules.
fix
Run: npm install webpack-require-weak
TypeError: webpackRequireWeak is not a function
Default import incorrect in certain environments.
fix
Use: const webpackRequireWeak = require('webpack-require-weak').default;
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
is-webpack-bundleoptionalUsed to check if running inside webpack bundle before using resolveWeak
Agent activity
9 hits · last 30 days
node
8
Resources
webpack-require-weak — npm install webpack-require-weak · libregistry