Check which version of Webpack is installed using NPM

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
3 min

banner

# Check which version of Webpack is installed

Use the npx webpack --version command to check which version of Webpack is installed. The command outputs the version number of webpack, webpack-cli and webpack-dev-server.

Open your terminal in your project's root directory and run the following command.

shell
npx webpack --version # ๐Ÿ‘‡๏ธ same as above npx webpack -v

check webpack version

You can use the npx webpack --help command to list the available commands.

shell
npx webpack --help
Make sure to prefix all webpack commands with npx.

You can also use the npm ls command to check your locally installed webpack version.

shell
npm ls webpack npm ls webpack-cli npm ls webpack-dev-server

You can check the version of webpack without its dependencies by setting the --depth argument to 0.

shell
npm ls webpack --depth=0 npm ls webpack-cli --depth=0 npm ls webpack-dev-server --depth=0

get webpack versions with depth 0

# Checking the version of the globally installed webpack module

If you need to check the version of a globally installed webpack package, use the npm ls -g webpack command.

shell
# ๐Ÿ‘‡๏ธ check which version of `webpack` is installed globally npm ls -g webpack # ๐Ÿ‘‡๏ธ list the versions of all globally installed packages npm ls -g

# Checking the version of webpack in your package.json file

You can also check the version of your locally installed webpack packages in the devDependencies object in your package.json file.

check webpack version in package json

If you need to install webpack locally to your project, open your terminal in your project's root directory and run the following command.

shell
# ๐Ÿ‘‡๏ธ install webpack npm install webpack --save-dev # ๐Ÿ‘‡๏ธ install the latest version of `webpack` npm install webpack@latest --save-dev

if you get an error when running the command, you can repeat it with the --legacy-peer-deps flag.

shell
# ๐Ÿ‘‡๏ธ install webpack npm install webpack --save-dev --legacy-peer-deps # ๐Ÿ‘‡๏ธ install the latest version of webpack npm install webpack@latest --save-dev --legacy-peer-deps

# Viewing the available webpack versions

If you need to get the latest version of webpack, use the npm view webpack version command.

shell
npm view webpack version

If you want to list all versions of the webpack package, use the npm view webpack versions command.

shell
npm view webpack versions npm view webpack versions --json

If you want to install a specific version of webpack, use the @ symbol to specify the version.

shell
npm install webpack@5.75.0 --save-dev # ๐Ÿ‘‡๏ธ if you get an error npm install webpack@5.75.0 --save-dev --legacy-peer-deps

If you need to update webpack to the latest version, use the following command.

shell
npm install webpack@latest --save-dev # ๐Ÿ‘‡๏ธ if you get an error npm install webpack@latest --save-dev --legacy-peer-deps

You can use the npm outdated command to list the current version and the latest version of your npm packages.

shell
npm outdated

You can use the npm update command to update your locally installed packages or the npm update -g command to update your globally installed NPM packages.

shell
# ๐Ÿ‘‡๏ธ update ALL locally installed packages npm update # ๐Ÿ‘‡๏ธ update ALL globally installed packages npm update -g

The npm update command follows the version constraints specified in your package.json file.

If you want to update all packages in your project to the latest version, use the npm-check-updates package.

Open your terminal in your project's root directory (where your package.json file is) and run the following command.

You can add your package.json file to version control (e.g. git) because the following 2 commands will update the versions of your packages in your package.json file.
shell
npx npm-check-updates -u npm install --legacy-peer-deps

The commands update all package versions in your package.json file to the latest version and install the packages.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev