# Is web3 ESM-only? Can you require() it?

> web3@4.16.0 ships CommonJS and ESM builds. Dual package — require() works on every Node.js version we test; import works too.

Ethereum JavaScript API

Last verified Sep 9, 2026 against web3@4.16.0.

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.

## Facts

- 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

## Runtime test results for web3@4.16.0

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:

```js
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:

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

- [web3 on npm](https://www.npmjs.com/package/web3)
- [Source repository](https://github.com/ChainSafe/web3.js)
- [HTML version](https://canirequire.com/package/web3/)
- [JSON version](https://canirequire.com/package/web3.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
