canirequire

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

  1. 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.
  2. TypeScript: types are bundled; install nothing extra.
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.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).

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") 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

Similar popularity