canirequire

canirequireDual (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.

Latest
4.16.0 (Dec 3, 2024)
Module format
Dual (CommonJS + ESM)
Last CommonJS version
4.16.0
Native ESM since
4.0.1
TypeScript types
Bundled
Node engines
>=14.0.0
Weekly downloads
662K
License
LGPL-3.0

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.

Runtimerequire("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).

VersionsFormatFirst published
4.0.1 – 4.16.0Dual (CommonJS + ESM)Jun 7, 2023
1.2.6 – 1.10.4CommonJSFeb 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

Similar popularity