canirequire

canirequireESM-only › hardhat

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

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. JSON

ESM-only ESM-only since 3.0.0 — last CommonJS version is 2.29.1

hardhat dropped its CommonJS build in 3.0.0 (August 2025). The last version you can require() on every Node.js version, including 18 and older, is 2.29.1, published Aug 18, 2026.

require("hardhat") fails even on Node.js 20.19+ / 22.12+ because the package uses top-level await, which require(esm) cannot load. Use import() instead.

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

Does hardhat@3.16.0 actually load? Runtime test results

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

Runtimerequire("hardhat")import "hardhat"
Node.js 18✗ failsERR_REQUIRE_ESM✗ failsSyntaxError
Node.js 20✗ failsERR_REQUIRE_ASYNC_MODULE✗ failsHardhatError
Node.js 22✗ failsERR_REQUIRE_ASYNC_MODULE✗ failsHardhatError
Node.js 24✗ failsERR_REQUIRE_ASYNC_MODULE✗ failsHardhatError
Node.js 26✗ failsERR_REQUIRE_ASYNC_MODULE✗ failsHardhatError
Bun 1.4✗ failsTypeError✗ failsHardhatError

How to import hardhat

ES modules (import)

import hardhat from "hardhat";

CommonJS (require)

// Node.js 20.19+ / 22.12+ / newer (package has no top-level await):
const hardhat = require("hardhat");

// Any Node.js version:
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).

VersionsFormatFirst published
3.0.0 – 3.16.0ESM-onlyAug 13, 2025
2.28.3 – 2.29.1CommonJSJan 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 you can require() on every Node.js version, including 18 and older, 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?

Use a dynamic import: const mod = await import("hardhat"). On Node.js 20.19+, 22.12+ and newer, a plain require("hardhat") also works for ESM packages that do not use top-level await. Alternatively pin hardhat@2.29.1.

Does hardhat work in Bun?

Importing hardhat failed in Bun 1.4 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

Other esm-only packages

Similar popularity