webpack

CLI Tool

webpack/webpack

A powerful static module bundler for JavaScript and associated assets.

Overview

Webpack bundles JavaScript modules and other assets for browser usage, supporting ES modules, CommonJS, AMD, and more. It offers code splitting for on-demand loading and a rich loader/plugin ecosystem for preprocessing and extending the build pipeline.

README Preview

\n  \n    \n  \n  \n  \n\n[![npm][npm]][npm-url]\n\n[![node][node]][node-url]\n[![builds1][builds1]][builds1-url]\n[![dependency-review][dependency-review]][dependency-review-url]\n[![coverage][cover]][cover-url]\n[](https://pkg.pr.new/~/webpack/webpack)\n[![PR's welcome][prs]][prs-url]\n[](https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/about-dependabot-security-updates#about-compatibility-scores)\n[](https://npmcharts.com/compare/webpack?minimal=true)\n[](https://packagephobia.com/result?p=webpack)\n[](https://opencollective.com/webpack#backer)\n[](https://opencollective.com/webpack#sponsors)\n[](https://github.com/webpack/webpack/graphs/contributors)\n[](https://github.com/webpack/webpack/discussions)\n[](https://discord.gg/5sxFZPdx2k)\n[](https://insights.linuxfoundation.org/project/webpack)\n\n  webpack\n  \n    Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.\n  \n\n\n## Table of Contents\n\n- [Install](#install)\n- [Introduction](#introduction)\n- [Concepts](#concepts)\n- [Contributing](#contributing)\n- [Support](#support)\n- [Current project members](#current-project-members)\n  - [TSC (Technical Steering Committee)](#tsc-technical-steering-committee)\n  - [Core Collaborators](#core-collaborators)\n- [Sponsoring](#sponsoring)\n  - [Premium Partners](#premium-partners)\n  - [Gold Sponsors](#gold-sponsors)\n  - [Silver Sponsors](#silver-sponsors)\n  - [Bronze Sponsors](#bronze-sponsors)\n  - [Backers](#backers)\n- [Special Thanks](#special-thanks-to)\n\n## Install\n\nInstall with npm:\n\n```bash\nnpm install --save-dev webpack\n```\n\nInstall with yarn:\n\n```bash\nyarn add webpack --dev\n```\n\n## Introduction\n\nWebpack is a bundler for modules. The main purpose is to bundle JavaScript\nfiles for usage in a browser, yet it is also capable of transforming, bundling,\nor packaging j

FAQ (5)

Troubleshooting
How do I fix “error:0308010C:digital envelope routines::unsupported” in webpack with Node.js 17?

This error occurs because older webpack versions use MD4 hashing, which is disabled by OpenSSL 3 in Node.js 17. Upgrade webpack to 5.61.0 or newer: npm install webpack@^5.61.0 --save-dev, then rebuild. As a temporary workaround, use Node.js 16 (nvm use 16) or enable the legacy OpenSSL provider: on Linux/macOS run export NODE_OPTIONS=--openssl-legacy-provider; on Windows CMD run set NODE_OPTIONS=--openssl-legacy-provider; in PowerShell run $env:NODE_OPTIONS="--openssl-legacy-provider". Then run your build again.

GitHub Issue #14532
Troubleshooting
How to fix Terser "DefaultsError: `as` is not a supported option" after upgrading to webpack 5.111.1?

Upgrade minimizer-webpack-plugin to version 5.12.0 or newer; the regression was present in 5.8.0. With Yarn, run:

yarn up minimizer-webpack-plugin@^5.12.0

With npm:

npm install minimizer-webpack-plugin@^5.12.0 -D

Then reinstall dependencies and rebuild. Verify the resolved version with yarn why minimizer-webpack-plugin or npm ls minimizer-webpack-plugin. Updating from 5.8.0 to 5.12.0 resolves the invalid as: 'script' option passed to Terser when minifying JavaScript embedded in HTML.

GitHub Issue #22288
Troubleshooting
Why does webpack stats.hasErrors() return true after the processErrors hook removes all errors?

This is a webpack 5 bug, reproduced in webpack 5.111.1. Stats.hasErrors() reads compilation.errors directly, while stats.toJson().errors and getErrors() apply the compilation.hooks.processErrors waterfall hook. Therefore, filtering errors in processErrors removes them from the output but does not change hasErrors().

The fix is to route hasErrors() through getErrors(), matching hasWarnings():

hasErrors() {
  return (
    this.compilation.getErrors().length > 0 ||
    this.compilation.children.some((child) => child.getStats().hasErrors())
  );
}

Upgrade webpack to a release containing the fix for issue #22279. Until then, do not rely on stats.hasErrors() when a plugin filters errors through processErrors. Use the processed error list instead:

function hasProcessedErrors(compilation) {
  return (
    compilation.getErrors().length > 0 ||
    compilation.children.some(hasProcessedErrors)
  );
}

const hasErrors = hasProcessedErrors(stats.compilation);

Alternatively, check the rendered stats output with stats.toJson().errors.length, accounting for child compilations if your build uses them.

GitHub Issue #22279
Troubleshooting
Why does webpack's browserslist target `safari 10` report `const`/`let` as unsupported while `safari 10.0` reports them supported?

This is a bug in webpack's browserslistTargetHandler (confirmed in webpack 5.111.1 and main). When a target has only a major version, such as safari 10, its missing minor version becomes NaN. In the equal-major check, NaN >= 0 is false, so features first supported at [10, 0] are incorrectly considered unsupported.

Fix: treat a missing minor version as 0 before comparing:

const parserMinor = Number(parser.minor ?? 0);

if (
  Number(parserMajor) === requiredVersion[0] &&
  parserMinor >= requiredVersion[1]
) {
  // feature is supported
}

Apply the upstream patch for webpack issue #22278 or use patch-package until a fixed webpack release is available. As a temporary workaround, use an explicit minor version where possible, such as safari 10.0, though some Browserslist queries may normalize it back to a bare major version.

GitHub Issue #22278
Troubleshooting
How to fix webpack crash "TypeError: Cannot read properties of null (reading 'userRequest')" when using CSS @import with experiments.css?

This is a webpack bug in native CSS mode (experiments.css: true). When a CSS rule uses parser: { exportType: "style" } and an @import "./ignored.css" target is ignored (via IgnorePlugin or resolve.alias: { "...": false }), moduleGraph.getModule(dep) returns null and CssGenerator._generateImportExpressions crashes reading depModule.userRequest. Fixes: 1) Upgrade webpack to the release containing this fix (PR for issue #22842 adds a null check). 2) Temporary patch: in node_modules/webpack/lib/css/CssGenerator.js, inside _generateImportExpressions, add if (!depModule) continue; right after const depModule = moduleGraph.getModule(dep); (use patch-package to persist it). 3) Alternative workaround: stop ignoring the CSS file—remove the IgnorePlugin/resolve.alias: false entry for that stylesheet, or switch the rule to exportType: "css-style-sheet" / "link" if feasible, since the crash only occurs with exportType: "style".

GitHub Issue #22842