Last modified: Jun 26, 2025 By Alexander Williams

Fix Error: Cannot find module 'webpack-cli'

If you see the error Cannot find module 'webpack-cli', don't worry. This is a common issue in Node.js projects. This guide will help you fix it quickly.

What causes this error?

The error occurs when Node.js cannot locate the webpack-cli package. This usually happens when the package is not installed or not properly linked.

Webpack CLI is required to run webpack commands. Without it, your build process will fail.

How to fix the error

Here are the most effective solutions to resolve this issue:

1. Install webpack-cli locally

First, try installing webpack-cli in your project:


npm install webpack-cli --save-dev

This adds webpack-cli to your devDependencies. After installation, try running your webpack command again.

2. Install webpack-cli globally

If local installation doesn't work, try installing it globally:


npm install -g webpack-cli

Global installation makes webpack-cli available system-wide. This can help if your system PATH has issues.

3. Check your package.json

Ensure webpack-cli is listed in your package.json under devDependencies:


"devDependencies": {
  "webpack-cli": "^4.9.0"
}

If it's missing, run npm install after adding it manually.

4. Verify node_modules

Sometimes, the node_modules folder gets corrupted. Delete it and reinstall:


rm -rf node_modules
npm install

5. Check webpack and webpack-cli versions

Version conflicts can cause this error. Ensure compatibility between webpack and webpack-cli:


npm list webpack webpack-cli

If you see similar errors like Cannot find module 'webpack', check all related packages.

Common troubleshooting steps

If the error persists, try these additional steps:

Clear npm cache

A corrupted cache can cause installation issues:


npm cache clean --force

Use yarn instead of npm

Sometimes switching package managers helps:


yarn add webpack-cli --dev

Check Node.js version

Ensure you're using a supported Node.js version. Webpack 5 requires Node.js 10.13.0 or later.

Example scenario

Here's a complete example of fixing the error:


# First, check if webpack-cli is installed
npm list webpack-cli

# If not found, install it
npm install webpack-cli --save-dev

# Verify installation
npx webpack --version

Output should show webpack and webpack-cli versions:


webpack: 5.75.0
webpack-cli: 4.10.0

Conclusion

The Cannot find module 'webpack-cli' error is easy to fix. Most often, installing the package solves it. Remember to check versions and dependencies.

Similar errors like Cannot find module 'react' or Cannot find module 'eslint' follow the same troubleshooting steps.

Always keep your development environment updated. This prevents many common Node.js errors.