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

> hardhat@3.16.0 is ESM-only. ESM-only since 3.0.0 — last CommonJS version is 2.29.1.

Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.

Last verified Sep 9, 2026 against hardhat@3.16.0.

hardhat dropped its CommonJS build in 3.0.0 (August 2025). The last version with a plain require()-able CommonJS entry is 2.29.1, published Aug 18, 2026.

require("hardhat") fails even on Node.js 20.19+, 22.12+ and newer: the package uses top-level await, which require(esm) cannot load (ERR_REQUIRE_ASYNC_MODULE). Use import() instead. On Node.js 18, which has no require(esm), require("hardhat") fails with ERR_REQUIRE_ESM.

## What to do

1. require("hardhat") fails even on Node.js 20.19+, 22.12+ and newer: the package uses top-level await, which require(esm) cannot load (ERR_REQUIRE_ASYNC_MODULE). Use import() instead.
2. From a CommonJS file, use a dynamic import inside an async function: const hardhat = await import("hardhat"). That works on every Node.js version the package supports.
3. If you need a synchronous require() or run Node.js 18: npm install hardhat@2.29.1, the last CommonJS release (published Aug 18, 2026).
4. TypeScript: types are bundled; install nothing extra.

## Facts

- Latest: 3.16.0 (Sep 7, 2026)
- Module format: ESM-only
- Last CommonJS version: 2.29.1
- ESM-only since: 3.0.0 (Aug 13, 2025)
- TypeScript types: bundled
- Node engines: not declared
- Weekly downloads: 374K
- License: MIT

## Runtime test results for hardhat@3.16.0

Installed and executed on Sep 9, 2026 with require("hardhat") from a CommonJS file and import "hardhat" from an ES module.

| Runtime | require("hardhat") | import "hardhat" |
|---|---|---|
| Node.js 18 | fails (ERR_REQUIRE_ESM) | fails (SyntaxError) |
| Node.js 20 | fails (ERR_REQUIRE_ASYNC_MODULE) | fails (HardhatError) |
| Node.js 22 | fails (ERR_REQUIRE_ASYNC_MODULE) | fails (HardhatError) |
| Node.js 24 | fails (ERR_REQUIRE_ASYNC_MODULE) | fails (HardhatError) |
| Node.js 26 | fails (ERR_REQUIRE_ASYNC_MODULE) | fails (HardhatError) |
| Bun 1.4.0 | fails (TypeError) | fails (HardhatError) |

## How to import hardhat

ES modules:

```js
import * as hardhat from "hardhat";
```

Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.

CommonJS:

```js
// Node.js 20.19+, 22.12+ and newer cannot require() this package: it uses top-level await.

// Any Node.js version the package supports, from an async function:
async function main() {
  const hardhat = await import("hardhat");
}

// Or pin the last CommonJS release:
// npm install hardhat@2.29.1
```

## Module format by version

Derived from the type, main and exports fields of every stable release on npm (196 versions; the newest 60 shown).

| Versions | Format | First published |
|---|---|---|
| 3.0.0 – 3.16.0 | ESM-only | Aug 13, 2025 |
| 2.28.3 – 2.29.1 | CommonJS | Jan 8, 2026 |

## Frequently asked

**Is hardhat ESM-only?**

hardhat@3.16.0 is ESM-only. hardhat dropped its CommonJS build in 3.0.0 (August 2025). The last version with a plain require()-able CommonJS entry is 2.29.1, published Aug 18, 2026.

**Which version of hardhat still supports CommonJS / require()?**

2.29.1 is the last version of hardhat with a CommonJS build. Install it with "npm install hardhat@2.29.1". Every version from 3.0.0 on is ESM-only.

**How do I use hardhat from a CommonJS file?**

From a CommonJS file, use a dynamic import inside an async function: const hardhat = await import("hardhat"). That works on every Node.js version the package supports. require("hardhat") fails even on Node.js 20.19+, 22.12+ and newer: the package uses top-level await, which require(esm) cannot load (ERR_REQUIRE_ASYNC_MODULE). Use import() instead. Alternatively pin hardhat@2.29.1.

**Does hardhat work in Bun?**

Importing hardhat failed in Bun 1.4.0 on Sep 9, 2026: HardhatError: HHE3: No Hardhat config file found.

**Does hardhat ship TypeScript types?**

Yes. hardhat bundles its own type declarations; no @types package is needed.

## Links

- [hardhat on npm](https://www.npmjs.com/package/hardhat)
- [Source repository](https://github.com/NomicFoundation/hardhat)
- [HTML version](https://canirequire.com/package/hardhat/)
- [JSON version](https://canirequire.com/package/hardhat.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.
