Skip to content
Quasar Tools Logo

How to Check Webpack Version

Every method for checking your webpack version: npx, npm list, package.json, lock files, and reading it programmatically inside a config or CI pipeline.

DH
Tutorials & How-Tos12 min read2,600 words

Knowing which webpack version your project is running matters more than most developers realise. Version mismatches between webpack, its loaders, and its plugins are one of the most common causes of cryptic build errors — errors that vanish the moment you align everything to the same major version. This guide covers every method for checking your webpack version: from a single terminal command to inspecting lock files, reading the webpack config, and understanding what the version number actually means for your build.

< 5sTime to check versionWith any method below
5Webpack major versionsv1 through v5
4→5Most common migrationBreaking changes require care

Why your webpack version matters

Webpack's five major versions are not drop-in replacements for each other. Each major release introduced breaking changes to configuration syntax, loader compatibility, and plugin APIs. A webpack 4 config will not work with webpack 5 without modifications, and loaders published for webpack 3 may fail silently or produce incorrect output in webpack 4+.

Beyond configuration compatibility, the webpack version affects performance. Webpack 5 introduced persistent caching, Module Federation, and improved tree-shaking that can cut build times and bundle sizes significantly compared to webpack 4. If you are debugging a slow build or investigating a bundle size regression, confirming the version is the first diagnostic step.

When version conflicts cause errors

  • Loader incompatibility — `babel-loader` v8 targets webpack 4; using it with webpack 5 without updating causes silent misconfiguration.
  • Plugin API mismatches — plugins that hook into the webpack compiler use an API that changed between v4 and v5. A plugin built for v4 will throw on a v5 compiler object.
  • Peer dependency conflicts — tools like `webpack-dev-server`, `html-webpack-plugin`, and `mini-css-extract-plugin` all publish versions tied to specific webpack majors.
  • CSS Loader schema errors — css-loader v5 and v6 have strict schema validation; a version mismatch with webpack produces the "ValidationError: Invalid options object" error.

Note

If you recently upgraded Node.js and your webpack build started failing, the Node.js version compatibility matrix is also worth checking. Webpack 4 dropped support for Node.js below v6; webpack 5 requires Node.js 10.13 or higher. Most actively maintained projects now require Node.js 14+.

How to check webpack version from the terminal

The terminal is the fastest and most reliable way to check your webpack version. There are three commands worth knowing, each suited to a slightly different situation.

Webpack is installed locally in your project as a devDependency. The globally installed version, if any, is almost never what your build is actually using.

Webpack documentation

The project-local version (most reliable)

Your project almost certainly installs webpack as a local devDependency, not a global package. To check the version that your build scripts actually use, run `npx` or `./node_modules/.bin/webpack` directly from the project root. These commands bypass any global webpack installation and report the locally installed version.

Check locally installed webpack version
bash
# Most reliable — uses the local node_modules install
npx webpack --version

# Alternative path-based invocation
./node_modules/.bin/webpack --version

# Using yarn
yarn webpack --version

# Pnpm
pnpm exec webpack --version

The npm list command

`npm list webpack` queries your local `node_modules` and prints the installed version alongside its position in the dependency tree. This is useful when you want to see not just the version but also which package required webpack as a peer dependency — a common source of version conflicts when a build tool depends on a specific webpack range.

Check webpack version with npm list
bash
# Show webpack version in local node_modules
npm list webpack

# Show all packages in the tree that depend on webpack
npm list webpack --all

# Yarn equivalent
yarn list --pattern webpack

# Pnpm equivalent
pnpm list webpack

The globally installed version

If you installed webpack globally with `npm install -g webpack webpack-cli`, you can check that version separately. Be aware that the global version is rarely the one your project builds use — most build scripts invoke webpack through `package.json` scripts, which always resolve to the local installation.

Check globally installed webpack
bash
# Global install check
webpack --version

# Or explicitly from the global path
npm list -g webpack

Warning

Never assume the output of `webpack --version` (without `npx`) is the version your project uses. If your PATH resolves to a globally installed webpack, the reported version may be completely different from the one in your project's `node_modules`. Always use `npx webpack --version` from your project root for an accurate result.

How to find the webpack version in package.json

Your project's `package.json` file lists the webpack version range your project declared as a dependency. This is not the same as the installed version — it is the range that was specified when webpack was added, and the actual installed version may be any version within that range.

1

Open package.json and look in devDependencies

Webpack is almost always listed under `devDependencies`, not `dependencies`. Open your `package.json` and look for a `"webpack"` key in the `devDependencies` block. The value is a semver range — `"^5.88.0"` means "any version compatible with 5.88.0", while `"5.88.0"` (no caret) pins to exactly that version.

Typical webpack entry in package.json
json
{
  "devDependencies": {
    "webpack": "^5.88.0",
    "webpack-cli": "^5.1.4",
    "webpack-dev-server": "^4.15.1"
  }
}
2

Check the lock file for the exact resolved version

The `package.json` range tells you the declared constraint. The lock file — `package-lock.json`, `yarn.lock`, or `pnpm-lock.yaml` — tells you the exact version that was actually installed. Search for `"webpack"` in your lock file to find the resolved version string. This is the version that every machine cloning the repo will install, making it the most authoritative record of what is running.

Find exact version in lock files
bash
# In package-lock.json (npm)
grep '"webpack"' package-lock.json | head -5

# In yarn.lock
grep 'webpack@' yarn.lock | head -5

# In pnpm-lock.yaml
grep 'webpack' pnpm-lock.yaml | head -10
3

Validate your package.json dependency ranges

If you want to audit the health of all dependencies in your `package.json` — not just webpack — the package.json Dependency Health Checker on Quasar Tools analyses your entire dependency list for risky version patterns, floating ranges, deprecated packages, and reproducibility gaps. Paste your `package.json` and get an actionable health report in seconds.

package.json Dependency Health Checker

Paste your package.json to detect risky version ranges, deprecated dependencies, and reproducibility gaps — entirely in your browser with no uploads.

Open tool

Checking the webpack version from within a config or script

Sometimes you need to know the webpack version at build time — for example, to apply a different configuration branch depending on the major version, or to log diagnostic information in a CI pipeline. Webpack exposes its version as a property on the compiler object, and the webpack package itself exports a `version` string.

Reading the version in webpack.config.js

webpack.config.js — log or branch on version
javascript
const webpack = require('webpack');

// The version string is available directly
console.log('Webpack version:', webpack.version);

// Use it to conditionally apply configuration
const isWebpack5 = parseInt(webpack.version, 10) >= 5;

module.exports = {
  // ...
  plugins: [
    isWebpack5
      ? new webpack.ids.DeterministicModuleIdsPlugin()
      : new webpack.HashedModuleIdsPlugin(),
  ],
};

Reading the version in a custom plugin or loader

Inside a webpack plugin, the compiler object carries the webpack version via `compiler.webpack.version`. This is the safest programmatic check because it reads the version of the webpack instance that invoked the plugin — not whatever version happens to be installed in `node_modules`.

Reading version inside a webpack plugin
javascript
class MyPlugin {
  apply(compiler) {
    // compiler.webpack is available in webpack 5+
    const version = compiler.webpack?.version ?? webpack.version;
    console.log('Running on webpack', version);

    compiler.hooks.done.tap('MyPlugin', (stats) => {
      // Build complete
    });
  }
}

Tip

If you are writing a plugin or loader that needs to support both webpack 4 and webpack 5, check `compiler.webpack` — it exists in v5 but not v4. Use that as the version signal rather than parsing the version string, since string parsing is fragile with pre-release identifiers.

Checking version in a CI environment

In a CI pipeline, the cleanest way to log the webpack version is to add a step that runs `npx webpack --version` and captures the output. This gives you the locally installed version from the exact `node_modules` that the build will use, and it appears in the pipeline log for every run — useful for debugging build failures that only appear on certain runners.

GitHub Actions — log webpack version before build
yaml
steps:
  - uses: actions/checkout@v4
  - uses: actions/setup-node@v4
    with:
      node-version: '20'
  - run: npm ci
  - name: Log webpack version
    run: npx webpack --version
  - name: Build
    run: npm run build

Webpack major versions compared

Understanding the differences between webpack major versions helps you decide whether your current version is appropriate for your project, and what to expect if you migrate. Here is a concise comparison of the capabilities and compatibility landscape across all five major releases.

VersionNode.js RequiredStatusKey Feature
webpack 1Any (very old)⛔ EOLOriginal CommonJS bundler
webpack 2Node.js ≥4⛔ EOLES module tree-shaking
webpack 3Node.js ≥6⛔ EOLScope hoisting, dynamic imports
webpack 4Node.js ≥6⚠️ Maintenance onlyZero-config mode, performance
webpack 5Node.js ≥10.13✓ ActiveModule Federation, persistent cache

Webpack 4 vs webpack 5 — key differences

  • Persistent caching — webpack 5 caches compilation results to disk between runs; a warm cache can make rebuilds 5–10× faster than webpack 4.
  • Module Federation — webpack 5 introduced Module Federation for sharing code between independently deployed frontends at runtime.
  • Asset modules — webpack 5 replaces `file-loader`, `url-loader`, and `raw-loader` with built-in asset module types (`asset/resource`, `asset/inline`, etc.).
  • Node.js polyfills removed — webpack 5 no longer automatically polyfills Node.js core modules. Projects that depended on polyfills for `buffer`, `path`, `stream`, etc. must add them explicitly.
  • Long-term caching — webpack 5 uses deterministic chunk IDs by default, producing stable file names across builds that improve browser cache hit rates.

Note

Webpack 4 is still widely used and receives occasional security fixes, but no new features. If you are starting a new project in 2026, use webpack 5. If you are on webpack 4 and the migration cost is high, staying on 4 is a valid choice — but plan the upgrade before tooling support for webpack 4 plugins begins to erode.

Troubleshooting webpack version conflicts

Version conflicts between webpack and its ecosystem are the most common source of confusing build errors. Most of these errors trace back to one of three root causes: multiple webpack copies in `node_modules`, a loader or plugin built for a different major version, or a peer dependency range mismatch.

Multiple webpack copies in node_modules

It is possible — and surprisingly common — to have more than one copy of webpack installed in your project. This happens when a dependency declares a peer dependency on webpack with a different major version range than your project uses. The result is two incompatible webpack instances, which causes plugins to silently fail or crash because they are registered against one instance but invoked by another.

Detect multiple webpack installs
bash
# Check for multiple webpack entries in the full dep tree
npm list webpack --all

# Look for more than one unique version number in the output
# e.g., both [email protected] and [email protected] appearing
# is a sign of conflicting peer dependencies

Resolving peer dependency conflicts

When `npm list webpack --all` shows multiple webpack versions, look at which package is pulling in the older version. Update that package to a version that supports your webpack major, or use the `resolutions` field (Yarn) or `overrides` field (npm 8+) to force all packages to use a single webpack version.

Force a single webpack version — npm overrides
json
{
  "overrides": {
    "webpack": "^5.88.0"
  }
}
Force a single webpack version — Yarn resolutions
json
{
  "resolutions": {
    "webpack": "^5.88.0"
  }
}

Validating semver ranges

Peer dependency ranges like `"webpack": "^4 || ^5"` and `"webpack": ">=4.41.0 <6"` are valid semver expressions but easy to misread. The Semver Validator on Quasar Tools checks any version string or range expression against the Semver 2.0.0 specification — useful when you are writing a library that declares a webpack peer dependency range and want to confirm the expression is correctly formed.

Warning

If you use `npm install --legacy-peer-deps` to bypass peer dependency errors, you may be silently installing incompatible versions. Resolve the actual conflict rather than suppressing the error — the build may work initially but produce subtle bugs or fail in production when a code path that relies on the incompatible package is executed.

Semver Validator

Validate any semantic version string or range expression against the Semver 2.0.0 spec — instantly in your browser.

Open tool

Best practices for managing webpack versions

Knowing your current webpack version is just the start. Managing it well — so that the version stays consistent across environments, is visible to every contributor, and is updated deliberately rather than accidentally — requires a few simple practices.

  1. Pin exact versions in devDependencies — use `"webpack": "5.88.2"` rather than `"^5.88.0"` for build-critical tools. Floating ranges let patches change the installed version between `npm install` runs on different machines, making build output non-deterministic.
  2. Commit your lock file — `package-lock.json`, `yarn.lock`, or `pnpm-lock.yaml` must be committed to version control. Without it, contributors and CI servers install different patch versions.
  3. Log the version in CI — add a `npx webpack --version` step before every build job. The version appears in every CI log, making it easy to correlate build failures with version changes.
  4. Audit dependencies after upgrades — when you update webpack, immediately run `npm list webpack --all` to confirm no secondary copies crept in, and run `npx webpack --version` to confirm the new version is what your build is using.
  5. Read the migration guide before upgrading — every webpack major version has an official migration guide at `webpack.js.org`. Read it before upgrading — not after the build breaks.

Tip

When a teammate reports a build error you cannot reproduce, the first question is: what does `npx webpack --version` output on their machine? Version drift between developer machines is one of the most common sources of "works on my machine" build failures in JavaScript projects.

JavaScript Beautifier

Format and indent minified or messy JavaScript in your browser — useful when inspecting webpack output bundles or generated config files.

Open tool

Key takeaways

  • Use `npx webpack --version` from your project root to check the locally installed version — never rely on the global `webpack --version` output.
  • `npm list webpack` shows the installed version and its position in the dependency tree; `npm list webpack --all` reveals if multiple conflicting copies exist.
  • The lock file (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`) contains the exact resolved version — more authoritative than the range in `package.json`.
  • Webpack 5 is the current active release; webpack 4 is maintenance-only. Key webpack 5 additions include persistent caching, Module Federation, and built-in asset modules.
  • Multiple webpack copies in `node_modules` cause silent plugin failures — detect with `npm list webpack --all` and fix with `overrides` (npm) or `resolutions` (Yarn).
  • Pin exact webpack versions in devDependencies and commit your lock file to ensure every developer and CI runner uses the same version.
  • Always check the webpack version first when debugging a build error — a version mismatch between webpack and a loader or plugin is the cause more often than the error message suggests.

Frequently Asked Questions

Run `npx webpack --version` from your project root directory. This takes under five seconds and reports the exact version installed in your local `node_modules` — the version your build scripts actually use. Make sure to run it from the project root, not from a subdirectory, so npx resolves to the correct local installation rather than a parent directory or global install.

`webpack --version` (without npx) resolves webpack from your system PATH, which may point to a globally installed version. `npx webpack --version` resolves webpack from the local `node_modules` in your current directory. Most projects install webpack locally as a devDependency, so the local version is what your build uses. Always prefer `npx webpack --version` when you need to know which version is actually building your project.

Require the webpack package at the top of your config and read `webpack.version`. For example: `const webpack = require("webpack"); console.log(webpack.version);`. Inside a plugin, use `compiler.webpack.version` instead — this reads the version of the webpack instance that invoked the plugin rather than whatever version is in `node_modules`, which is safer in monorepo setups where multiple webpack versions may coexist.

Your `package.json` contains a semver range like `"^5.88.0"`, which permits any compatible version. For the exact installed version, check your lock file: search for `"webpack"` in `package-lock.json` (npm), `webpack@` in `yarn.lock`, or `webpack:` in `pnpm-lock.yaml`. The resolved version string in the lock file is what was actually downloaded and is the authoritative version across all machines that install from that lock file.

Multiple webpack versions in your dependency tree means two or more packages installed different webpack majors as nested dependencies. This causes conflicts because plugins and loaders hook into the webpack compiler object — if different parts of your build use different webpack instances, plugins registered against one will not run in the other. Fix this by updating the conflicting package to a version that supports your webpack major, or use the `overrides` field in package.json (npm 8+) to force a single version.

Use webpack 5. It is the only actively developed version and brings substantial improvements: persistent disk caching for fast rebuilds, Module Federation for micro-frontend architectures, built-in asset modules that replace file-loader and url-loader, and better tree-shaking. Webpack 4 is in maintenance mode and receives only security fixes. New tooling and plugins increasingly require webpack 5, and the webpack 4 ecosystem is gradually eroding.

css-loader v5 and above use strict option schema validation and are designed for webpack 5. If you run css-loader v5+ with webpack 4, you will see a "ValidationError: Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema" error. The fix is either to downgrade css-loader to the version compatible with your webpack major, or to upgrade webpack to v5. Check the css-loader release notes for the exact webpack peer dependency range each version targets.

Add a `run: npx webpack --version` step in your CI configuration immediately after the `npm ci` or `npm install` step. In GitHub Actions, add it as a named step — "Log webpack version" — so the version is clearly visible in the job log. This takes seconds and gives you a permanent record of the webpack version used in every build, which is invaluable when diagnosing build regressions that appeared after a dependency update.

ShareXLinkedIn

Related articles