Registry / devops / webpack-require-from

webpack-require-from

JSON →
library1.8.6jsnpmunverified

Webpack plugin to control dynamic import chunk paths/URLs at runtime. v1.8.6 supports Webpack 2-5 and web workers. Lightweight, zero dependencies, production-tested. Unlike static output.publicPath, it allows runtime path overrides via a fixed path, a global variable, or a global method. Last release in 2021; stable maintenance mode.

npm install webpack-require-from
INSTALL
IMPORT
SIG · WEBPACK-REQUIRE-FR
W
webpack-require-from
devopsjavascriptv1.8.6
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.

WebpackRequireFrom
const WebpackRequireFrom = require('webpack-require-from');
import WebpackRequireFrom from 'webpack-require-from';
Package is CJS-only; ESM import will fail. Use require().
WebpackRequireFrom
const WebpackRequireFrom = require('webpack-require-from').default;
const WebpackRequireFrom = require('webpack-require-from');
For TypeScript projects with esModuleInterop, default export may need .default. Check your TS config.
WebpackRequireFrom as default
import WebpackRequireFrom = require('webpack-require-from');
import WebpackRequireFrom from 'webpack-require-from';
When using TypeScript, use import = require() syntax for CJS modules.

Configures Webpack to resolve dynamic import chunks using a global function that can be defined at runtime.

// webpack.config.js const WebpackRequireFrom = require('webpack-require-from'); module.exports = { output: { publicPath: '/static/', }, plugins: [ new WebpackRequireFrom({ methodName: 'getChunkURL', }), ], }; // In your browser code: window.getChunkURL = function(chunkName) { return 'https://cdn.example.com/chunks/' + chunkName; };
Debug
Known issues
breakingv1.3.1: 'supressErrors' option renamed to 'suppressErrors' (typo fix). Old name still works but deprecated.
fix
Use 'suppressErrors' instead of 'supressErrors'.
affects: >=1.3.1
deprecatedv1.3.1: moved tapable from dependencies to peerDependencies. Ensure tapable@^2.2.0 is installed.
fix
npm install tapable@^2.2.0
affects: >=1.3.1
gotchaThe options 'path', 'variableName', and 'methodName' are mutually exclusive. Only one can be used at a time.
fix
Provide only one of these options in the plugin config.
affects: >=1.0.0
gotchaVariableName option must be a global variable name; it is evaluated at runtime. Ensure the variable exists before dynamic imports occur.
fix
Define the variable on window or globalThis before any dynamic import.
affects: >=1.0.0
gotchaFor Webpack 5, ensure your Webpack version is compatible; v1.8.2 added Webpack 5 support.
fix
Use v1.8.2 or later for Webpack 5.
affects: >=1.8.2
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'tapable'
tapable is a peer dependency and not automatically installed.
fix
Install tapable as a dev dependency: npm install tapable@^2.2.0 --save-dev
TypeError: webpackRequireFrom is not a constructor
Using ES module import syntax on a CJS module with default export.
fix
Use require('webpack-require-from') or for TypeScript: import WebpackRequireFrom = require('webpack-require-from')
Uncaught ReferenceError: chunkURL is not defined
Variable specified in 'variableName' option is not defined globally at runtime.
fix
Define window.chunkURL = 'your/path/' before any dynamic import.
Upgrade
Version history
1.8.6latest on npm
Audit
Dependencies
tapablerequiredpeer dependency for Webpack plugin compatibility
Agent activity
9 hits · last 30 days
node
8
Resources
webpack-require-from — npm install webpack-require-from · libregistry