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. Markdown · JSON
Dual (CommonJS + ESM) Dual package — require() works on every Node.js version we test; import works too
web3 publishes both a CommonJS entry and a native ESM entry (ESM added in 4.0.1). require("web3") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >=14.0.0. import "web3" works alongside it.
What to do
- Nothing to change. require("web3") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >=14.0.0. import * as web3 from "web3" works alongside it; use named imports for what the ESM entry exports.
- TypeScript: types are bundled; install nothing extra.
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.0 | ✓ works | ✓ works |
How to import web3
ES modules (import)
import * as web3 from "web3";Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.
CommonJS (require)
const web3 = require("web3");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 (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") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >=14.0.0. import "web3" works alongside it.
Can I require web3?
Yes. web3 ships a CommonJS entry alongside the native ESM entry. require("web3") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >=14.0.0.
Does web3 work in Bun?
Yes. import "web3" loaded successfully in Bun 1.4.0 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
- 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
- font-awesome 4.7.0No entry
- babel-plugin-add-module-exports 1.0.4CommonJS
- gulp-sourcemaps 3.0.0CommonJS
- tape 5.10.2CommonJS
- @babel/node 8.0.1No entry
- rollup-plugin-node-resolve 5.2.0CommonJS
- browser-sync 3.0.4CommonJS
- jest-styled-components 7.4.0CommonJS