p-webpack
raw JSON → 1.0.1 verified Sat Apr 25 auth: no javascript
p-webpack is a thin wrapper that adds Promise support to Webpack's compile API (versions 1-4). Version 1.0.1 is the current stable release. It accepts the same configuration options as Webpack and returns a Promise that resolves with the compilation stats. It is a minimal, no-dependency library that simply promisifies the callback-based compiler.run(). Unlike alternatives like webpack-promise or manual wrapping, p-webpack focuses only on the run method and maintains full compatibility with Webpack's options object. It is suitable for Node.js 4+ and requires Webpack as a peer dependency.
Common errors
error TypeError: webpack is not a function ↓
cause Incorrect import: destructured named export instead of default.
fix
Change 'const { webpack } = require("p-webpack")' to 'const webpack = require("p-webpack")'.
error Error: Cannot find module 'webpack' ↓
cause Missing webpack peer dependency.
fix
Run 'npm install webpack' in your project.
Warnings
gotcha Requires webpack as a peer dependency. Must install webpack separately. ↓
fix Run 'npm install webpack' alongside p-webpack.
gotcha Only works with webpack 1-4. Does not support webpack 5's new compiler API. ↓
fix Use webpack's native promise support or upgrade to a newer wrapper.
gotcha Does not support multi-compiler or watch mode. Only wraps the single run() callback. ↓
fix Use webpack's own multi-compiler or watch APIs directly for those features.
Install
npm install p-webpack yarn add p-webpack pnpm add p-webpack Imports
- default wrong
const webpack = require('p-webpack')correctimport webpack from 'p-webpack' - p-webpack wrong
const { webpack } = require('p-webpack')correctconst webpack = require('p-webpack')
Quickstart
const webpack = require('p-webpack');
const fs = require('fs');
async function build() {
try {
const stats = await webpack({
entry: './src/index.js',
output: {
path: __dirname + '/dist',
filename: 'bundle.js'
}
});
console.log('Build completed:', stats.toString({ colors: true }));
} catch (err) {
console.error('Build failed:', err);
}
}
build();