{"id":20480,"library":"promise-loader","title":"promise-loader","description":"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.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/gaearon/promise-loader","tags":["javascript"],"install":[{"cmd":"npm install promise-loader","lang":"bash","label":"npm"},{"cmd":"yarn add promise-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add promise-loader","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import load from 'promise!./file.js';","symbol":"promise-loader","correct":"const load = require('promise?bluebird!./file.js');"},{"note":"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.","wrong":"const load = require('promise?bluebird!./editor.js'); // missing chunk name","symbol":"promise-loader with chunk name","correct":"const load = require('promise?bluebird,editor!./editor.js');"},{"note":"Use the 'loader' property in a rule. The query string includes the promise library and optional chunk name pattern with [filename] or [name] substitutions.","wrong":"{ test: /\\.json$/, loader: 'promise?bluebird' }","symbol":"promise-loader as a loader in webpack config","correct":"{ test: /\\.i18n\\.json$/, loader: 'promise?global,[name].i18n' }"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  entry: './index.js',\n  output: {\n    filename: 'bundle.js',\n    path: __dirname + '/dist'\n  },\n  module: {\n    loaders: [\n      {\n        test: /\\.async\\.js$/,\n        loader: 'promise?bluebird'\n      }\n    ]\n  }\n};\n\n// index.js\nvar load = require('./some.async.js');\nload().then(function(module) {\n  console.log(module);\n}).catch(function(err) {\n  console.error(err);\n});","lang":"javascript","description":"This shows how to configure promise-loader in Webpack to load files ending with .async.js lazily using Bluebird promises."},"warnings":[{"fix":"Add a parameter like 'bluebird', 'Q', or 'global' to the loader query: require('promise?bluebird!./file.js').","message":"You must specify a promise library as a query parameter; there is no default.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Always use the returned function and await its promise. If you need synchronous loading, use bundle-loader instead.","message":"Only 'lazy' mode is supported; unlike bundle-loader you cannot get an immediate synchronous require.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"Loader query syntax with '?' and ',' may be deprecated in newer Webpack versions in favor of options or resourceQuery.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Ensure a global Promise is present, either via native Promise or a polyfill like core-js or es6-promise.","message":"The 'global' promise parameter uses window.Promise; if unavailable, it will fail.","severity":"breaking","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install the promise-loader package: npm install promise-loader --save-dev. Then use require('promise?bluebird!./file.js') with the loader prefix.","cause":"The 'promise' package is not installed as a node_modules package; the loader is not being invoked correctly.","error":"Module not found: Error: Cannot resolve module 'promise'"},{"fix":"Add a query string with a promise library, e.g., require('promise?bluebird!./file.js'). Then load() returns a Promise.","cause":"The query parameter to specify the promise library is missing, causing the loader to return the module directly instead of a loading function.","error":"TypeError: load is not a function"},{"fix":"Install the promise library: npm install bluebird. Alternatively, use 'global' if you have a global Promise.","cause":"The specified promise library (e.g., 'bluebird') is not installed or not available in the project's dependencies.","error":"Cannot find module 'bluebird'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}