canirequire › Dual (CommonJS + ESM) › web3
Is web3 ESM-only? Can you require() it?
Ethereum JavaScript API
Last verified Sep 9, 2026 against web3@4.16.0. JSON
Dual (CommonJS + ESM) Dual package — both require() and import work
web3 publishes both a CommonJS entry and a native ESM entry (ESM added in 4.0.1). require("web3") and import "web3" both work on every supported Node.js version and in Bun.
Does web3@4.16.0 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("web3") from a CommonJS file and import "web3" from an ES module.
| Runtime | require("web3") | import "web3" |
|---|---|---|
| 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 | ✓ works | ✓ works |
How to import web3
ES modules (import)
import web3 from "web3";CommonJS (require)
const web3 = require("web3");Module format by version
Derived from the type, main and exports fields of every stable release on npm (116 versions; the newest 60 shown).
| Versions | Format | First published |
|---|---|---|
| 4.0.1 – 4.16.0 | Dual (CommonJS + ESM) | Jun 7, 2023 |
| 1.2.6 – 1.10.4 | CommonJS | Feb 2, 2020 |
Frequently asked
Is web3 ESM-only?
web3@4.16.0 ships CommonJS and ESM builds. web3 publishes both a CommonJS entry and a native ESM entry (ESM added in 4.0.1). require("web3") and import "web3" both work on every supported Node.js version and in Bun.
Can I require web3?
Yes. web3 ships a CommonJS entry, so require("web3") works on every Node.js version, alongside the native ESM entry for import.
Does web3 work in Bun?
Yes. import "web3" loaded successfully in Bun 1.4 on Sep 9, 2026.
Does web3 ship TypeScript types?
Yes. web3 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
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
- js-yaml 5.4.1Dual
Similar popularity
- font-awesome 4.7.0CommonJS
- babel-plugin-add-module-exports 1.0.4CommonJS
- gulp-sourcemaps 3.0.0CommonJS
- tape 5.10.2CommonJS
- rollup-plugin-node-resolve 5.2.0CommonJS
- browser-sync 3.0.4CommonJS
- jest-styled-components 7.4.0CommonJS
- babel-plugin-transform-flow-strip-types 6.22.0CommonJS