canirequire › Dual (CommonJS + ESM) › web-vitals
Is web-vitals ESM-only? Can you require() it?
Easily measure performance metrics in JavaScript
Last verified Sep 9, 2026 against web-vitals@6.2.1. Markdown · JSON
Dual (CommonJS + ESM) Dual package — require() works on every Node.js version we test; import works too
web-vitals publishes both a CommonJS entry and a native ESM entry (ESM added in 0.1.0). require("web-vitals") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "web-vitals" works alongside it.
What to do
- Nothing to change. require("web-vitals") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import * as webVitals from "web-vitals" works alongside it; use named imports for what the ESM entry exports.
- TypeScript: types are bundled; install nothing extra.
Does web-vitals@6.2.1 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("web-vitals") from a CommonJS file and import "web-vitals" from an ES module.
| Runtime | require("web-vitals") | import "web-vitals" |
|---|---|---|
| Node.js 18 | ✓ works | ✓ works |
| Node.js 20 | ✓ works | ✓ works |
| Node.js 22 | ✓ works | ✓ works |
| Node.js 24 | ✓ works | ✓ works |
| Node.js 26 | ✓ works | ✓ works |
| Bun 1.4.0 | ✓ works | ✓ works |
How to import web-vitals
ES modules (import)
import * as webVitals from "web-vitals";Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.
CommonJS (require)
const webVitals = require("web-vitals");Module format by version
Derived from the type, main and exports fields of every stable release on npm, corrected where a runtime test of that version contradicted them (54 versions; the newest 54 shown).
| Versions | Format | First published |
|---|---|---|
| 3.0.0 – 6.2.1 | Dual (CommonJS + ESM) | Aug 24, 2022 |
| 0.2.2 – 2.1.4 | CommonJS | May 12, 2020 |
| 0.1.0 – 0.2.1 | ESM-only | Apr 24, 2020 |
Frequently asked
Is web-vitals ESM-only?
web-vitals@6.2.1 ships CommonJS and ESM builds. web-vitals publishes both a CommonJS entry and a native ESM entry (ESM added in 0.1.0). require("web-vitals") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "web-vitals" works alongside it.
Can I require web-vitals?
Yes. web-vitals ships a CommonJS entry alongside the native ESM entry. require("web-vitals") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun.
Does web-vitals work in Bun?
Yes. import "web-vitals" loaded successfully in Bun 1.4.0 on Sep 9, 2026.
Does web-vitals ship TypeScript types?
Yes. web-vitals bundles its own type declarations; no @types package is needed.
Links
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- tslib 2.8.1Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
Similar popularity
- @pkgr/core 0.3.6Dual
- @babel/plugin-transform-classes 8.0.1ESM-only
- @smithy/property-provider 4.5.2CommonJS
- immediate 3.3.0CommonJS
- @tootallnate/once 3.0.1ESM-only
- react-transition-group 4.4.5CommonJS
- postcss-nested 8.0.1ESM-only
- @jest/globals 30.5.1CommonJS