canirequire

canirequire › ESM-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. Markdown · 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 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.
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.0✗ failsTypeError✗ failsHardhatError

How to import hardhat

ES modules (import)

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 (require)

// 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, corrected where a runtime test of that version contradicted them (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 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

Other esm-only packages

Similar popularity