Update Browserslist DB
update-browserslist-db is a dedicated CLI tool designed to keep the `caniuse-lite` database up-to-date, which is crucial for modern front-end development workflows. Many build tools and development processes rely on Browserslist configurations (e.g., `last 2 versions`, `>1%`) to target specific browser features. These queries, in turn, depend on accurate and current data from `caniuse-lite`. This package ensures that the underlying browser compatibility data is refreshed, preventing stale targets and potential mismatches in transpilation or polyfilling. The current stable version is 1.2.3, with an active release cadence addressing compatibility across different package managers (npm, pnpm, yarn) and runtimes (Node.js, Bun). Its key differentiator is being the official, single-purpose tool for this specific and vital maintenance task within the Browserslist ecosystem, often run as a postinstall script or via a manual `npx` command.
Common errors
-
ERR_PNPM_NO_PACKAGE_IN_DEPENDENCIES
cause This error occurs when using pnpm with older versions of `update-browserslist-db` or an incompatible `browserslist` peer dependency, where pnpm's dependency resolution might fail due to package linking issues.fixUpgrade `update-browserslist-db` to version 1.2.1 or newer, and ensure your project's `peerDependencies` include `browserslist: ">=4.21.0"` to meet compatibility requirements.
Warnings
- gotcha Early versions of `update-browserslist-db` had inconsistent or broken support for Bun, leading to update failures or unexpected behavior when run in Bun environments. This was addressed incrementally across several releases.
- gotcha When using pnpm, some earlier versions could unexpectedly modify `package.json` or fail to update correctly, especially with specific `depth` configurations or when used with older Browserslist versions. This could lead to build failures or incorrect browser data.
- gotcha Older Node.js environments (specifically pre-1.0.16) might encounter compatibility issues, preventing the `update-browserslist-db` tool from running successfully or completing its update process.
Install
-
npm install update-browserslist-db -
yarn add update-browserslist-db -
pnpm add update-browserslist-db
Imports
- update-browserslist-db
import { updateBrowserslistDb } from 'update-browserslist-db'npx update-browserslist-db@latest
Quickstart
/*
This CLI tool is typically run in your project's root directory to update the 'caniuse-lite' data.
It is often included as a 'postinstall' script in package.json or run manually when browser support data needs refreshing.
*/
console.log("Updating caniuse-lite and Baseline data...");
// 1. Using npx (Node.js/npm - recommended for one-off or scripts)
// npx automatically installs the package if not found and runs it.
// Command to run in your terminal:
// npx update-browserslist-db@latest
// 2. If using pnpm
// Command to run in your terminal:
// pnpm exec update-browserslist-db latest
// 3. If using yarn
// Command to run in your terminal:
// yarn dlx update-browserslist-db@latest
// Example of how to add it to package.json scripts:
/*
{
"name": "my-project",
"version": "1.0.0",
"scripts": {
"postinstall": "update-browserslist-db"
},
"peerDependencies": {
"browserslist": ">=4.21.0"
}
}
*/