Registry / web-framework / promise-loader

promise-loader

JSON →
library1.0.0jsnpmunverified

A Webpack loader that provides a promise-based alternative to bundle-loader for code splitting. It wraps lazy-loaded chunks behind a function that returns a Promise<module>, allowing you to control when the chunk is fetched. The loader requires a promise library parameter (e.g., 'bluebird', 'Q', or 'global'). Supports named chunks and filename/name substitutions in bundle names. Stable version 1.0.0, by Dan Abramov. Useful for single-page apps needing promise-based lazy loading with Webpack.

npm install promise-loader
INSTALL
IMPORT
SIG · PROMISE-LOADER
P
promise-loader
web-frameworkjavascriptv1.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.

promise-loader
const load = require('promise?bluebird!./file.js');
import load from 'promise!./file.js';
This is a Webpack loader, not a module. You 'require' it with a query parameter specifying the promise library. ESM import will not work directly; use require or configure in webpack.config.js.
promise-loader with chunk name
const load = require('promise?bluebird,editor!./editor.js');
const load = require('promise?bluebird!./editor.js'); // missing chunk name
Chunk name is optional but if omitted, the chunk will have a numeric id. Specify as a comma-separated second parameter after the promise library.
promise-loader as a loader in webpack config
{ test: /\.i18n\.json$/, loader: 'promise?global,[name].i18n' }
{ test: /\.json$/, loader: 'promise?bluebird' }
Use the 'loader' property in a rule. The query string includes the promise library and optional chunk name pattern with [filename] or [name] substitutions.

This shows how to configure promise-loader in Webpack to load files ending with .async.js lazily using Bluebird promises.

// webpack.config.js module.exports = { entry: './index.js', output: { filename: 'bundle.js', path: __dirname + '/dist' }, module: { loaders: [ { test: /\.async\.js$/, loader: 'promise?bluebird' } ] } }; // index.js var load = require('./some.async.js'); load().then(function(module) { console.log(module); }).catch(function(err) { console.error(err); });
Debug
Known issues
breakingYou must specify a promise library as a query parameter; there is no default.
fix
Add a parameter like 'bluebird', 'Q', or 'global' to the loader query: require('promise?bluebird!./file.js').
affects: >=0.1.0
gotchaOnly 'lazy' mode is supported; unlike bundle-loader you cannot get an immediate synchronous require.
fix
Always use the returned function and await its promise. If you need synchronous loading, use bundle-loader instead.
affects: >=0.1.0
deprecatedLoader query syntax with '?' and ',' may be deprecated in newer Webpack versions in favor of options or resourceQuery.
fix
For Webpack 5+, consider using a custom rule with the 'use' property and options object, or use a different loader like @webpack-contrib/promise-loader.
affects: >=0.1.0
breakingThe 'global' promise parameter uses window.Promise; if unavailable, it will fail.
fix
Ensure a global Promise is present, either via native Promise or a polyfill like core-js or es6-promise.
affects: >=0.1.0
Errors
Common errors & fixes
Module not found: Error: Cannot resolve module 'promise'
The 'promise' package is not installed as a node_modules package; the loader is not being invoked correctly.
fix
Install the promise-loader package: npm install promise-loader --save-dev. Then use require('promise?bluebird!./file.js') with the loader prefix.
TypeError: load is not a function
The query parameter to specify the promise library is missing, causing the loader to return the module directly instead of a loading function.
fix
Add a query string with a promise library, e.g., require('promise?bluebird!./file.js'). Then load() returns a Promise.
Cannot find module 'bluebird'
The specified promise library (e.g., 'bluebird') is not installed or not available in the project's dependencies.
fix
Install the promise library: npm install bluebird. Alternatively, use 'global' if you have a global Promise.
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
promise-loader — npm install promise-loader · libregistry